DocsCommonutilitiesAssertNever
Package: @hexos/common

Exhaustiveness check helper for discriminated union switch statements.

Place in the default case of a switch over a discriminated union. If a new variant is added to the union but not handled, TypeScript emits a compile-time error because the value is no longer assignable to never. Always throws at runtime as a safety net.

Example

type Status = 'pending' | 'completed' | 'error';
function handle(s: Status) {
  switch (s) {
    case 'pending': return 'waiting';
    case 'completed': return 'done';
    case 'error': return 'failed';
    default: return assertNever(s);
  }
}
function assertNever(value: never): never

Parameters

value

never