typescript-eslint: [no-unused-vars] false positive when a type is used in a generic position on a method in a class with `emitDecoratorMetadata: true`
- I have tried restarting my IDE, and the issue persists.
- I have updated to the latest version of the packages.
- I have read the FAQ and my problem is not listed.
The problem reported in https://github.com/typescript-eslint/typescript-eslint/issues/2947 has not been solved by https://github.com/typescript-eslint/typescript-eslint/pull/2943. It remains the same as before.
Repro
If AppState is imported:
import {AppState} from '@m-kbase/shared/general/states';
and later used only in a constructor, like:
constructor(
private _store: Store<AppState>
) {}
then the warning appears in many places (in relation to the import {AppState} from '@m-kbase/shared/general/states'; line):
warning 'AppState' is defined but never used @typescript-eslint/no-unused-vars
Expected Result
The same result as with the previous version 4.13.0 or earlier, with no warnings.
Versions
| package | version |
|---|---|
@typescript-eslint/eslint-plugin |
4.14.1 |
@typescript-eslint/parser |
4.14.1 |
TypeScript |
4.1.3 |
ESLint |
7.18.0 |
node |
12.13.1 |
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 28 (11 by maintainers)
Commits related to this issue
- fix(scope-manager): correctly reference generic parameters when decorator metadata is enabled Fixes #2972 — committed to typescript-eslint/typescript-eslint by bradzacher 6 years ago
- fix(scope-manager): correctly reference generic parameters when decorator metadata is enabled (#2975) Fixes #2972 — committed to typescript-eslint/typescript-eslint by bradzacher 6 years ago
Cool! With @chunghha’s repro case I’m able to reproduce this now.
The issue is only occurring for users that are using type-aware linting AND are using
emitDecoratorMetadata.This highlights the value of providing as much detail as possible in the initial post and in follow up comments. In this instance - I was unable to repro this because what was required was both the ESLint config and TS config.
The more information you can give when you file an issue - the more likely it is that the maintainer can look into it sooner.
The OP contained minimal information - two one-line code fragments, and that was it. Which meant that I could not reproduce it.
If they had provided their configs (ESLint and TS), then I wouldn’t have had to wait for others to provide a repro.
Never be afraid to dump as much info as you have. All of it. Just dump it. It’s much better to sift through information to find what’s relevant, rather than get no information and have to burn time on a back-and-forth asking for more info.
@bradzacher here is a repo to reproduce. https://github.com/chunghha/nest-gql/commit/1978ca7c043df8a5c040f95cb51f855a177f61de “yarn lint” with the 4.13.0 throws no warnings/errors but with the 4.14.1 throws two warnings.
This has been fixed in #2975. This will release to the
latesttag on NPM next Monday (Feb 1st) as per our release schedule.If you need it ASAP, it has also been released to the
canarytag on NPM (4.14.2-alpha.1) To install it:4.14.2-alpha.1 appears to be working. Thanks.
New issue: https://github.com/typescript-eslint/typescript-eslint/issues/2994
@bradzacher It looks like that there is one special case, where
@typescript-eslint/no-unused-varsis falsy positive (and is probably also related to the context, what is the variable name and what is the type/interface/namespace/… name, because in this case, they are the same, but it’s allowed in TS in general).https://github.com/typescript-eslint/typescript-eslint/issues/2972#issuecomment-771725764
The showed repro has been working correctly in 4.13.0.
We have still the same issue in our Angular project.
IsMobile, DialogsService, UiState and WindowRef are reported as
no-unused-vars.please file a new issue, as it is unrelated to this closed issue
@mlc-mlapis Yes, I confirm. It worked.
@mlc-mlapis sorry for not having a repo. Here it is: https://github.com/kmaraz/no-unused-vars-issue I’ll show you the issue in the pictures:
This works as the class property
This does not work, as the class property
thisWorkshas different name from theTest.Testhas the same name asTestimport. Hope it helps! 😃The final version of 4.14.2 works as expected.
Thanks.
I can also confirm this.