blob: 406eca9f7fc99d27537cbd195025edc7e9b19a6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
/**
* Mark a branch as unreachable in an exhaustive switch. If the compiler
* ever allows this line to be reached, `value` stops being `never` and
* the call site fails to type-check — making exhaustive checks load-bearing
* at compile time.
*
* Usage:
* switch (kind) {
* case 'a': ...
* case 'b': ...
* default: assertNever(kind)
* }
*/
export function assertNever(value: never, message?: string): never {
throw new Error(message ?? `Unhandled case: ${String(value)}`)
}
|