typedash
Version:
modern, type-safe collection of utility functions
21 lines (20 loc) • 726 B
JavaScript
//#region src/functions/assertNever/assertNever.ts
/**
* Throws an error if a value is of type `never`.
* Used for exhaustive checks.
* @param inclusive The value to check.
* @param noThrow If `true`, returns `undefined` instead of throwing an error.
* @returns This function never returns a value, but throws an error if `inclusive` is of type `never`.
* @example
* ```typescript
* assertNever('foo' as never); // throws an error
* assertNever('foo' as never, true); // returns undefined
* ```
*/
function assertNever(inclusive, noThrow = false) {
if (noThrow) return;
throw new Error(`Unexpected inclusive value: ${inclusive}`);
}
//#endregion
export { assertNever as t };
//# sourceMappingURL=assertNever-o2Z9qguB.js.map