Closed
Description
Repro
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
"createDefaultProgram": true
},
"rules": {
"@typescript-eslint/no-unnecessary-type-assertion": "error"
}
}
let resolve: () => void;
const promise = new Promise((resolve1) => (resolve = resolve1));
resolve!();
Expected Result
No errors occur.
Actual Result
3:1 error This assertion is unnecessary since it does not change the type of the expression @typescript-eslint/no-unnecessary-type-assertion
Additional Info
Removing the !
will cause tsc --strict
to error with the following message:
test.ts(3,1): error TS2454: Variable 'resolve' is used before being assigned.
Related issues:
- False positives for
no-unnecessary-type-assertion
#187 - [no-unnecessary-type-assertion] false positive when asserting via non-null assertion operator #529
- [no-unnecessary-type-assertion] False positive with null/undefined union type #1061
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
2.3.3 |
@typescript-eslint/parser |
2.3.3 |
TypeScript |
3.6.4 |
ESLint |
6.5.1 |
node |
10.16.3 |
npm |
6.9.0 |