Throws a TypeScript error if an unreachable case is reached. Often used to ensure that a switch statement is exhaustive.
The value that should never be reached
type PossibleValues = 'a' | 'b';const handleValue = (value: PossibleValues) => { switch (value) { case 'a': return 'A'; case 'b': return 'B'; default: return unreachable(value); }}If 'c' is added to PossibleValues but not handled in the switch statement,TypeScript will throw an error. Copy
type PossibleValues = 'a' | 'b';const handleValue = (value: PossibleValues) => { switch (value) { case 'a': return 'A'; case 'b': return 'B'; default: return unreachable(value); }}If 'c' is added to PossibleValues but not handled in the switch statement,TypeScript will throw an error.
Throws a TypeScript error if an unreachable case is reached. Often used to ensure that a switch statement is exhaustive.