Skip to content

Bug: [no-unnecessary-type-assertion] does not detect unnecessary non-null-assertion on a call expression #8141

Closed
@lvjiaxuan

Description

@lvjiaxuan

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/no-unnecessary-type-assertion

Description

I propose that the no-unnecessary-type-assertion rule should also check for the return type of a function.

Fail

declare function foo(): number;
const a = foo()!; // no error report
const b = foo() as number; // report error but bad fixed: `const b = foo() ; `
const c = <number>foo(); // good now

Pass

declare function foo(): number;
const a = foo();
const b = foo();
const c = foo();

Additional Info

Im ready to send a PR after the issue is marked with the accepting prs label as indicated on the PR Checklist. Welcome to provide more test cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething 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