# switch-exhaustiveness-check

Rule `typescript/switch-exhaustiveness-check`. Require switch-case statements to be exhaustive

- Source: typescript
- Technologies: TypeScript
- Kind: suspicious
- Needs type information: yes
- Autofix: yes, in at least one linter
- Reach: 31.1M weekly downloads of presets that enable it
- Trend: +105.5% last quarter
- Rank: #466 by reach, #261 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `@typescript-eslint/switch-exhaustiveness-check` | no | suggestion | package `@typescript-eslint/eslint-plugin` | [docs](https://typescript-eslint.io/rules/switch-exhaustiveness-check) |
| Oxlint | `typescript/switch-exhaustiveness-check` | no | suggestion | plugin `typescript`, category pedantic | [docs](https://oxc.rs/docs/guide/usage/linter/rules/typescript/switch-exhaustiveness-check.html) |
| Biome | `nursery/useExhaustiveSwitchCases` | yes | unsafe | group nursery, since 2.0.0 | [docs](https://biomejs.dev/linter/rules/use-exhaustive-switch-cases/) |

## Code examples

### Incorrect: the rule reports this

```ts
const value: number = Math.floor(Math.random() * 3);

switch (value) {
  case 0:
    return 0;
  case 1:
    return 1;
}
```

```ts
type Day =
  | 'Monday'
  | 'Tuesday'
  | 'Wednesday'
  | 'Thursday'
  | 'Friday'
  | 'Saturday'
  | 'Sunday';

declare const day: Day;
let result = 0;

switch (day) {
  case 'Monday':
    result = 1;
    break;
}
```

```ts
enum Fruit {
  Apple,
  Banana,
  Cherry,
}

declare const fruit: Fruit;

switch (fruit) {
  case Fruit.Apple:
    console.log('an apple');
    break;
}
```

### Correct: the rule accepts this

```ts
declare const literal: 'a' | 'b';

switch (literal) {
  case 'a':
    break;
  default:
    break;
}
```

```ts
declare const value: 'a' | 'b';

switch (value) {
  case 'a':
    break;
  // skip default
}
```

```ts
// requires `considerDefaultExhaustiveForUnions` to be set to true

type Day =
  | 'Monday'
  | 'Tuesday'
  | 'Wednesday'
  | 'Thursday'
  | 'Friday'
  | 'Saturday'
  | 'Sunday';

declare const day: Day;
let result = 0;

switch (day) {
  case 'Monday':
    result = 1;
    break;
  default:
    result = 42;
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import tseslint from "typescript-eslint";

export default [
  {
    plugins: { "@typescript-eslint": tseslint.plugin },
    rules: {
      "@typescript-eslint/switch-exhaustiveness-check": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "typescript/switch-exhaustiveness-check": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "useExhaustiveSwitchCases": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Biome recommended](https://lintradar.dev/presets/biome-recommended.md) | Biome | `@biomejs/biome` | 491 | 28.5M | +106.8% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |

## Related rules

- [typescript/prefer-string-starts-ends-with](https://lintradar.dev/rules/typescript/prefer-string-starts-ends-with.md): Enforce using `String#startsWith` and `String#endsWith` over other equivalent methods of checking substrings
- [typescript/prefer-optional-chain](https://lintradar.dev/rules/typescript/prefer-optional-chain.md): Enforce using concise optional chain expressions instead of chained logical ands, negated logical ors, or empty objects
- [typescript/consistent-type-exports](https://lintradar.dev/rules/typescript/consistent-type-exports.md): Enforce consistent usage of type exports
- [typescript/consistent-type-imports](https://lintradar.dev/rules/typescript/consistent-type-imports.md): Enforce consistent usage of type imports
- [typescript/ban-types](https://lintradar.dev/rules/typescript/ban-types.md): This rule bans specific types and can suggest alternatives. Note that it does not ban the corresponding runtime objects from being used.
- [typescript/require-await](https://lintradar.dev/rules/typescript/require-await.md): Disallow async functions which do not return promises and have no `await` expression

---

Web page: https://lintradar.dev/rules/typescript/switch-exhaustiveness-check. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
