Skip to main content

typescript/exhaustive-switch

Require a default branch in switch statements with multiple cases.

Targeted pattern scope

This rule targets SwitchStatement nodes that:

  • have more than one case branch, and
  • have no default branch.

What this rule reports

This rule reports non-trivial switch statements that have no default case.

Why this rule exists

A required default branch reduces accidental non-exhaustive control flow.

❌ Incorrect

switch (x) {
case 1:
break;
case 2:
break;
}

✅ Correct

switch (x) {
case 1:
break;
default:
break;
}

Deprecated

Behavior and migration notes

This rule is deprecated in favor of @typescript-eslint/switch-exhaustiveness-check.

It reports only and does not provide an autofix.

Options

This rule has no options.

Status

Use the Deprecated section above for lifecycle details.

Additional examples

switch (status) {
case "ready":
return 1;
}
// ✅ valid (single branch switch is outside this rule)

switch (status) {
case "ready":
return 1;
case "done":
return 2;
}
// ❌ reported: multiple branches and no default

ESLint flat config example

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/typescript/exhaustive-switch": "error",
},
},
];

When not to use it

Disable this rule if you intentionally omit default cases.

Package documentation

Rule catalog ID: R084

Further reading

Adoption resources

  • Start at warning level in CI, then move to error after cleanup.
  • Use focused codemods/autofix batches per package or directory.