You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.mdx
+52-1Lines changed: 52 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ This rule reports when a `switch` statement over a value typed as a union of lit
23
23
If set to false, this rule will also report when a `switch` statement has a case for everything in a union and _also_ contains a `default` case. Thus, by setting this option to false, the rule becomes stricter.
24
24
25
25
When a `switch` statement over a union type is exhaustive, a final `default` case would be a form of dead code.
26
-
Additionally, if a new value is added to the union type, a `default` would prevent the `switch-exhaustiveness-check` rule from reporting on the new case not being handled in the `switch` statement.
26
+
Additionally, if a new value is added to the union type and you're using [`considerDefaultExhaustiveForUnions`](#considerDefaultExhaustiveForUnions), a `default` would prevent the `switch-exhaustiveness-check` rule from reporting on the new case not being handled in the `switch` statement.
Since `value` is a non-union type it requires the switch case to have a default clause only with `requireDefaultForNonUnion` enabled.
59
59
60
+
### `considerDefaultExhaustiveForUnions`
61
+
62
+
{/* insert option description */}
63
+
64
+
If set to true, a `switch` statement over a union type that includes a `default` case is considered exhaustive.
65
+
Otherwise, the rule enforces explicitly handling every constituent of the union type with their own explicit `case`.
66
+
Keeping this option disabled can be useful if you want to make sure every value added to the union receives explicit handling, with the `default` case reserved for reporting an error.
67
+
68
+
Examples of code with `{ considerDefaultExhaustiveForUnions: true }`:
0 commit comments