Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug: [no-unused-vars] Decorators are flagged as unused when it's actually used since TypeScript 4.8 #5496

Closed
@chenxinyanc

Description

@chenxinyanc

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=4.8.0-beta&sourceType=module&showAST=es&code=PTAEHIFkE8BEFMDGB7ATgQwC5vKAlgM6gAm8AZngHbzGgBGArpqNQG7yqgME0B0oAUQDKAGSrMAFAAFM0AA7wCiVHjmYAtIoA244JWTqGlbjXWt0qAgEoAsACgyRxJjzJKoGAhQZsqADwAKqDwAB6Y8JTERABiTi5uAHwSAPqYFgDm8JgAXFyUANb6AO6UADSgyfnw0LkEmCqU6eWkSipqaLkB8jQACqjICqiyCK2qvoEJVp3dxH0DHMOKymNoE6AA3vagoKhZDKjuLcvtqADc9gC+9vaIWugERDAAwncPG1ugUp5IaFhoH3IGHQdIhQNFkMgJFZ3nZtlc7PD7CBQAEABb9IoeaAve5EbCgTCo+D0O6IfKgVHILTwXj2VjIPDECTPV7WexAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tidmUQAmtAG4BDaKgwBtcNhyJo0DtEgAaWXKxzskMRPRRR8eGo3bI4gOaTDAM3wLu-Aae07KlztEQAlFPgBlSgAjRiZrA3w4RHU3HCtkAElPZUQABVF8B2gmA0gAPQB9VzjIMlFYSwALfABRRWUbSE4mREgzCABfMwBdWW7uoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkeAhpgObp4VTokBMADL5ABpwNSCTyZk0PADkArqlQBhABbpoAazKVxs9EJocAHoizJ46Ig1QARNbEz089rWB17htdPGR5bcB06YALKs9AAmjvTsbsIAviCxQA

Repro Code

// 'MyDecorator' is defined but never used. ESLint (@typescript-eslint/no-unused-vars)
function MyDecorator<T extends Function>(_target: unknown, _key: string, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> {
  return descriptor;
}

class MyClass {
  @MyDecorator
  public Foo() {
  }
}

// Throw MyClass to the black hole.
void(MyClass)

ESLint Config

{
  "rules": {
    "@typescript-eslint/no-unused-vars": [
      "error",
      {
        "vars": "all",
        "args": "after-used",
        "ignoreRestSiblings": true,
        "argsIgnorePattern": "^_",
        "caughtErrors": "none"
      }
    ]
  }
}

tsconfig

{
  "compilerOptions": {
    "target": "es2020",
    "strictNullChecks": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Expected Result

MyDecorator is used as decorator of MyClass.Foo.

Actual Result

'MyDecorator' is defined but never used. ESLint (@typescript-eslint/no-unused-vars)

Additional Info

I've just upgraded TypeScript from 4.7.4 to 4.8.1-rc and this lint error surfaces.

Versions

package version
@typescript-eslint/eslint-plugin 5.33.1
@typescript-eslint/parser 5.33.1
TypeScript 4.8.1-rc
ESLint 8.22.0
node 16.16.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions