Skip to content

require-assert-never

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

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.

Examples

Before — flagged Do not leave an exhaustive default empty
src/render.ts
declare const kind: "a" | "b";
switch (kind) {
case "a":
break;
case "b":
break;
default:
}
After — preferred Make the default exhaustive
src/render.ts
declare const kind: "a" | "b";
switch (kind) {
case "a":
break;
case "b":
break;
default:
assertNever(kind);
}