function exhaustiveCheck(x: never): never {
throw new Error('Unexpected value: ' + x)
}
// Place at the default branch to catch unhandled union membersAn exhaustive check using never ensures all union members are handled at compile time.
The never type is useful for exhaustiveness checking.
If a case reaches the never branch, TypeScript will emit a compile error.
Challenge: Implement exhaustiveCheck(x: never): never β a utility that throws at runtime while signaling exhaustiveness to TypeScript.
// Used in a switch default:
default: throw exhaustiveCheck(shape)