Skip to content
Functionutilsv0.10.0

assertNever

Exhaustiveness guard for discriminated unions. Place in the default branch of a switch over a union's discriminant: if a new variant is added without a matching case, the call fails to compile.

Throws:

  • A SeedcordTypeError whenever it runs. Only a value that the types ruled out can reach it.

assertNever(value: never): never
type Shape = { kind: 'circle' } | { kind: 'square' };

function area(shape: Shape): number {
  switch (shape.kind) {
    case 'circle': return Math.PI;
    case 'square': return 1;
    default: return assertNever(shape); // compile error if a Shape variant is added
  }
}