Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rule proposal:no-unnecessary-type-predicate #10398

Closed as not planned
Closed as not planned
Labels
duplicateThis issue or pull request already existsenhancement: new plugin ruleNew rule request for eslint-pluginlocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look
@elliotleelewis

Description

@elliotleelewis

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

My proposal is suitable for this project

  • My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
  • My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

I think there would be value in having a rule to avoid extra type-predicate checks when they're not necessary. This can help clean up type-predicates around a repo as types are changed, and also avoid unnecessary CPU cycles at runtime.

This rule would work similarly tono-unnecessary-type-assertion.

Fail Cases

consttest:"foo"="foo";constisFoo=(text:string):text is"foo"=>{returntext==="foo";}// Should error here: at compile time we know the else branch will never get hitif(isFoo(test)){console.log("FOO!");}else{console.log("BAR!");}

Pass Cases

consttest:string="bar";constisFoo=(text:string):text is"foo"=>{returntext==="foo";}// Shouldn't error here: at compile time we cannot know if the else branch will be hit, and so the predicate usage makes sense.if(isFoo(test)){console.log("FOO!");}else{console.log("BAR!");}

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already existsenhancement: new plugin ruleNew rule request for eslint-pluginlocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp