Skip to content

TypeScript · correctness

require-assert-never

eslint:require-assert-never

Require an empty switch default to call `assertNever` so discriminated unions remain exhaustive at compile time.

Default
error
Fix
none
Languages
typescript

Why

An empty default silently accepts new union members instead of making the compiler identify the missing case.

Fix

Call `assertNever` with the discriminant in the exhaustive switch default.

Before / after

Executed by this rule’s unit tests.

Before

Do not leave an exhaustive default empty

src/render.ts · focus
declare const kind: 'a' | 'b';
switch (kind) { case 'a': break; case 'b': break; default: }

After

Make the default exhaustive

src/render.ts · focus
declare const kind: 'a' | 'b';
switch (kind) { case 'a': break; case 'b': break; default: assertNever(kind); }

Message IDs

missingAssertNever