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

Skip to content

Bug: [consistent-type-imports] "used by decorator metadata" false positive for type used in constructor parameter #7327

@mpotthoff

Description

@mpotthoff

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.

Issue Description

When upgrading from typescript-eslint 5.x.x to 6.x.x I started seeing false positive errors "used by decorator metadata" for types that are used in constructor parameters, even if the class itself is not using any decorators at all.

So given these two files

export class ClassA {}
import type { ClassA } from "./classA";

export class ClassB {
    public constructor(classA: ClassA) {}
}

we would expect no errors, as no decorators are involved in either file.

Instead we get an error reported for the import of ClassA:

1:1  error  Type import "ClassA" is used by decorator metadata  @typescript-eslint/consistent-type-imports

Reproduction Repository Link

https://github.com/mpotthoff/consistent-type-imports-decorator-bug

Repro Steps

  1. clone the repo
  2. npm install
  3. npx eslint classB.ts

Versions

package version
@typescript-eslint/eslint-plugin 6.2.0
@typescript-eslint/parser 6.2.0
@typescript-eslint/scope-manager 6.2.0
@typescript-eslint/typescript-estree 6.2.0
@typescript-eslint/type-utils 6.2.0
@typescript-eslint/utils 6.2.0
TypeScript 5.1.6
ESLint 8.45.0
node 18.16.1

Metadata

Metadata

Labels

accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: scope-managerIssues related to @typescript-eslint/scope-manager

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions