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.
Issue Description
When using an imported deprecated variable inside an object to assign it to a field, the usage is not detected/reported by the rule, both in CLI (npx eslint
) and the VSCode ESLint extension.
When the variable is not imported, declared in the same file, the issue is reported correctly.
When using an intermediate variable, the issue is reported correctly.
The original case I was handling was in an Angular module forRoot
method returning a ModuleWithProviders
configuration object, so as to bind the now deprecated NGXS_PLUGINS
injection token from the NGXS library (since v18.1.6) to an implementation service/provider.
Reproduction Repository Link
https://github.com/StephaneSeyvoz/typescript-eslint-no-deprecated
Repro Steps
- clone the repo
npm install
npx eslint
or open in VSCode with the ESLint extension
src\main.ts
18:18 error `deprecatedVar` is deprecated. For some reason; Usually would be an Angular injection token @typescript-eslint/no-deprecated
24:26 error `deprecatedModuleVar` is deprecated. For some reason; Usually would be an Angular injection token @typescript-eslint/no-deprecated
45:16 error `deprecatedVar` is deprecated. For some reason; Usually would be an Angular injection token @typescript-eslint/no-deprecated
52:24 error `deprecatedModuleVar` is deprecated. For some reason; Usually would be an Angular injection token @typescript-eslint/no-deprecated
✖ 4 problems (4 errors, 0 warnings)
-> Lines 10 and 36 are not detected/reported
-> In VSCode, lines 10 and 36 are shown as deprecated by ts(6385)
, not ESLint
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
8.24.0 |
@typescript-eslint/parser |
8.24.0 |
@typescript-eslint/scope-manager |
8.24.0 |
@typescript-eslint/typescript-estree |
8.24.0 |
@typescript-eslint/type-utils |
8.24.0 |
@typescript-eslint/utils |
8.24.0 |
TypeScript |
5.7.3 |
ESLint |
9.20.1 |
node |
20.16.0 |
Quick self-analysis
I tried tracking the issue in the no-deprecated rule source for tag 8.24.0.
It fails in getDeprecationReason
while considering the node.parent.type
as a property.
When the variable is local / not imported, the getJsDocDeprecation(propertySymbol)
call at line 353 succeeds.
It returns undefined
when the variable is imported.
In the debugger, evaluating searchForDeprecationInAliasesChain
the same way as line 358 returns the right deprecation reason.
This seems related, as the comment above searchForDeprecationInAliasesChain
says:
// Deprecated jsdoc tags can be added on some symbol alias, e.g.
//
// export { /** @deprecated */ foo }
//
// When we import foo, its symbol is an alias of the exported foo (the one
// with the deprecated tag), which is itself an alias of the original foo.
// Therefore, we carefully go through the chain of aliases and check each
// immediate alias for deprecated tags
So I guess it's just about applying the right behaviour with imported properties.
Checking for duplicates
I found #10643, but:
- it seems different since no import is used there,
- the issue isn't here when the variable is local.
so I considered it was a different problem.