Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
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 havesearched for related issues and found none that matched my issue.
- I haveread the FAQ and my problem is not listed.
Playground Link
Repro Code
functioninjectable<T>():(target:T)=>void{returnfunction(target:T):void{};}import{Bar}from'./bar';// Error: All imports in the declaration are only used as types.@injectable()classFoo{constructor(privatebar:Bar){}}
ESLint Config
module.exports={parser:"@typescript-eslint/parser",rules:{"@typescript-eslint/consistent-type-imports":"error"},};
tsconfig
{"compilerOptions": {"strictNullChecks":true,"emitDecoratorMetadata":true,"experimentalDecorators":true }}
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';// okclassFoo{constructor(@deco(()=>Bar)privatebar:Bar){}}
import{Bar}from'./bar';// Expected ok, but got Error: All imports in the declaration are only used as types.@injectable()classFoo{constructor(privatebar:Bar){}}
Actual Result
The rule assumesBar
is used as a type, causing the DI library (in the casetsyringe) 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 |