@quentinadam/unreachable
v0.1.1
Published
A simple library to assert unreachable code paths
Readme
@quentinadam/unreachable
A simple library to assert unreachable code paths.
unreachable is meant for exhaustive checks. At compile time, TypeScript only accepts calls where the value has been
narrowed to never (no possible value left). If it is still reached at runtime, it throws an AssertionError.
Usage
import unreachable from '@quentinadam/unreachable';
function transform(value: number | string) {
if (typeof value === 'number') {
return value * 2;
}
if (typeof value === 'string') {
return value.toUpperCase();
}
return unreachable(value);
}