typescripteslinttypescript-genericstypescript-eslint

ESLint no-unused-vars error on TypeScript generic type


I have this simple object class which is meant to constrain possible values to a certain type:

export class Dictionary<T> {
    [key: string]: T
}

But ESLint is complaining about it with the error 1:25 error 'T' is defined but never used @typescript-eslint/no-unused-vars despite the fact that I'm using it on the very next line. Is this a bug in the linter, or am I doing something wrong?

I know I can just add a comment to ignore that line, but I would prefer to fix it "properly" if it's possible.

The rule is configured this way:

"rules": {
    "@typescript-eslint/no-unused-vars": [
        "error",
        {
            "ignoreRestSiblings": true
        }
    ],
    "no-unused-vars": "off"
}

Potentially relevant package versions:

"@angular-eslint/builder": "17.3.0",
"@angular-eslint/eslint-plugin": "17.3.0",
"@angular-eslint/eslint-plugin-template": "17.3.0",
"@angular-eslint/schematics": "17.3.0",
"@angular-eslint/template-parser": "17.3.0",
"@typescript-eslint/eslint-plugin": "7.2.0",
"@typescript-eslint/eslint-plugin-tslint": "7.0.2",
"@typescript-eslint/parser": "7.2.0",
"eslint": "8.57.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-deprecation": "2.0.0",
"typescript": "5.2.2"

Solution

  • It was reported as a bug here: https://github.com/typescript-eslint/typescript-eslint/issues/9811

    The team do not want to support Types, so their recommendation is to ignore the line:

    /* eslint-disable @typescript-eslint/no-unused-vars */
    export class Dictionary<T> {
      [key: string]: T
    }