Skip to content

[no-unnecessary-type-assertion] false positive on uninitialized variables #453

Closed
@mysticatea

Description

@mysticatea

Repro

{
  "rules": {
    "@typescript-eslint/no-unnecessary-type-assertion": "error"
  }
}
function test() {
    let resolve: () => void
    new Promise(resolve0 => {
        resolve = resolve0
    })
    return resolve!
}

Expected Result

No errors because it's a syntax error if I removed the !.

Actual Result

6:12  error  This assertion is unnecessary since it does not change the type of the expression  @typescript-eslint/no-unnecessary-type-assertion

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 1.7.0
@typescript-eslint/parser 1.7.0
TypeScript 3.4.3
ESLint 5.16.0
node 10.15.3
npm 6.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghas prthere is a PR raised to close thispackage: 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