Skip to content

[no-unnecessary-type-assertion] False positive with non-null-assertion #1066

Closed
@brainkim

Description

@brainkim

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions