Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Open
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
- 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-condition#checktypepredicates
Description
In no-unnecessary-condition's checkTypePredicates check, we currently only check for type predicates that are unnecessary (always-true) due to the argument already having the type in the predicate. I propose that we additionally check for cases that are unnecessary (always-false) due to the argument not having any overlap with the type in the predicate (if this is possible?).
Fail
declareconsts:string;declarefunctionisNumber(x:unknown):x isnumber;if(isNumber(s)){s;//^? never}
Pass
declareconsts:string|number;declarefunctionisNumber(x:unknown):x isnumber;if(isNumber(s)){s;//^? number}
Additional Info
This isn't justchecker.isAssignableTo(argumentType, predicateType)
because the logic is really whether the intersection of the argument type and predicate type is empty. Thinking about it, I'm unsure whether we can determine that?