Skip to content

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

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy