[no-unused-vars] report when runtime var is only used within a type (type MyType = typeof varName
)
#3325
Labels
accepting prs
Go ahead, send a pull request that resolves this issue
enhancement
New feature or request
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
Repro
Run it locally via https://github.com/happycollision/eslint-no-unused-vars-typescript-repro
Expected Result
An eslint error that
foo
is unused. (Just like it would if we removed the type def line.)Actual Result
No eslint error reported.
Additional Info
If you agree with my thoughts below, then this is a bug. If you disagree, then I guess it is a feature request that'd need some options to opt into it.
I am of the opinion that if you create a runtime variable, you ought to be expected to use that variable within your runtime code. Using a runtime variable for purely type definition purposes means that when your code is compiled (depending on your compiler of choice and options), you'll have an extra variable handing around that does nothing. In all likelihood, this is an error and you meant to use the variable but forgot to add it to whatever other part of your code needed it. This is exactly why I realized that this bug exists. 😄
I cannot think of a single case where you'd want such behavior, but I am totally willing to believe they might exist.
Versions
@typescript-eslint/eslint-plugin
4.22.0
@typescript-eslint/parser
4.22.0
TypeScript
4.2.4
ESLint
7.25.0
node
v11.12.0
The text was updated successfully, but these errors were encountered: