Closed
Description
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have read the FAQ and my problem is not listed.
Repro
{
"rules": {
"@typescript-eslint/switch-exhaustiveness-check": "warn"
}
}
type Day = string; // or number
const day = 'Monday' as Day;
let result = 0;
switch (day) {
case 'Monday': {
result = 1;
break;
}
}
or
type Day = any; // or unknown, or a JS variable outside of a TS context
const day = 'Monday' as Day;
let result = 0;
switch (day) {
case 'Monday': {
result = 1;
break;
}
}
Expected Result
I would expect to see an error message compatible with the default-case
ESLint rule, indicating that the switch-exhaustiveness-check rule is invalidated because the expression is not a union type.
Actual Result
No error message.
Additional Info
Essentially, I think the best of both worlds is to just have the predictable functionality of the default-case
rule operate normally except in the event that a switch statement's expression is a union type. Today, there doesn't seem to be any way for the two rules to operate in tandem. Adding this functionality might be a breaking change, but I'm honestly a bit curious how controversial it would be.