Closed
Description
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
Repro Code
function injectable<T>(): (target: T) => void {
return function (target: T): void {
};
}
import { Bar } from './bar'; // Error: All imports in the declaration are only used as types.
@injectable()
class Foo {
constructor(private bar: Bar) {}
}
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/consistent-type-imports": "error"
},
};
tsconfig
Expected Result
I expected that #2751 (#2559) would've fixed this and the rule wouldn't have assumed that it is only used as a type, but turns out it only catches decorators from within the constructor:
import { Bar } from './bar'; // ok
class Foo {
constructor(@deco(() => Bar) private bar: Bar) {}
}
import { Bar } from './bar'; // Expected ok, but got Error: All imports in the declaration are only used as types.
@injectable()
class Foo {
constructor(private bar: Bar) {}
}
Actual Result
The rule assumes Bar
is used as a type, causing the DI library (in the case tsyringe) to be unable to inject the dependencies (Bar
) at runtime. This is pretty similar to the issue with Nest.js (#2559)
Additional Info
No response
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
5.41.0 |
@typescript-eslint/parser |
playground default |
TypeScript |
4.8.4 |
ESLint |
8.15.0 |
node |
playground default |