/** * Function used to assert a given code path is unreachable */ export function unreachable(): never /** * Function used to assert a given code path is unreachable. * Very useful for ensuring switches are exhaustive: * * ```ts * switch (a.type) { * case Types.A: * case Types.B: * break * default: * unreachable(a) // will cause a build error if there was * // a Types.C that was not checked * } * ``` * * @param value Value to be asserted as unreachable */ // NOTE: Uses separate overloads, _not_ `value?: never`, to not allow `undefined` to be passed export function unreachable(value: never): never export function unreachable(value?: never): never { throw new Error( arguments.length === 0 ? 'unreachable' : `unreachable (${JSON.stringify(value)})`, ) }