Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
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
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I havesearched for related issues and found none that match my proposal.
- I have searched thecurrent rule list and found no rules that match my proposal.
- I haveread the FAQ and my problem is not listed.
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
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