Open lionel-rowe opened 1 year ago
I would love this lint rule, but unfortunately this would require access to type information that TypeScript provides but deno_lint cannot access.
For anyone else that stumbles on this issue, I figured out a workaround via adding a dummy default
clause. The non-exhaustive switch statement fails type checking with Type 'string' is not assignable to type 'never'.
Playground
type X = 'A' | 'B'
declare const x: X
// `Type 'string' is not assignable to type 'never'.`
switch (x) {
case 'A':
break
default: void ((): never => x)
}
// OK
switch (x) {
case 'A':
break
case 'B':
break
default: void ((): never => x)
}
// OK
switch (x) {
case 'A':
break
default:
break
}
Disallow non-exhaustive
switch
statements. Especially useful when expanding an enum/string union/numeric union type to allow new options.See https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md
Wrong ❌
OK ✅
OK ✅