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
Closed as not planned
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/switch-exhaustiveness-check/
Description
I propose that theswitch-exhaustiveness-check
checksswitch
statements that operate on non-union-types and require them to have a default case to ensure they are exhaustive.
Fail
constvalue:number=Math.floor(Math.random()*3);switch(value){case0:console.log("zero");return;case1:console.log("one");return;}
Pass
constvalue:number=Math.floor(Math.random()*3);switch(value){case0:console.log("zero");return;case1:console.log("one");return;default:console.log("higher");return;// Ordefault:// Do nothing}
Additional Info
Since it would break projects that have theswitch-exhaustiveness-check
enabled, but don't have all their switch statements fully exhaustive, this should probably locked behind a default false option. Maybe this could be turned on by default with the next major version.
This option can not be replaced withdefault-case
due to#7539.
Originally searched for during: