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
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I haveread the FAQ and my problem is not listed.
Repro
{"root":true,"parser":"@typescript-eslint/parser","parserOptions": {"ecmaVersion":2021,"project":"./tsconfig.json","sourceType":"module"},"plugins": ["@typescript-eslint"],"rules": {"@typescript-eslint/no-unnecessary-type-assertion":"error"}}
// code.tstypeFoo=3constfoox:Foo=3as3constfooy=3asFooconstfooz:Foo=3constfooa=<3>3constfoob=<Foo>3constfooc=3constbar=fooc!functionfoo(x:number):number{returnx!// unnecessary non-null}
{"compilerOptions": {"strict":true },"include": ["./code.ts" ],}
Expected Result
3:14 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion4:14 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion7:14 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion8:14 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion11:13 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion14:9 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion✖ 6 problems (6 errors, 0 warnings)
OR (see below)
3:14 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion4:14 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion5:7 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion7:14 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion8:14 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion11:13 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion14:9 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion✖ 7 problems (7 errors, 0 warnings)
Actual Result
11:13 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion 14:9 error This assertion is unnecessary since it does not change thetype of the expression @typescript-eslint/no-unnecessary-type-assertion✖ 2 problems (2 errors, 0 warnings)
Additional Info
ThetypesToIgnore
option description implies also checking annotations. Since annotations and assertions are different things, I would expect them to be handled by separate rules. Depending on whether or not they are an intended target for this rule, the first or second expectation should be fulfilled.
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin | 5.10.0 |
@typescript-eslint/parser | 5.10.0 |
TypeScript | 4.5.5 |
ESLint | 8.7.0 |
node | 14.17.5 ,16.13.2 |