/** * Asserts that a code path is unreachable by accepting a value of type `never`. * This function is useful for exhaustive checks in switch statements or discriminated unions. * If called, it throws an error with a message containing the unexpected value. * * @param x - The value that should never occur (of type `never`). * @throws {Error} Throws an error indicating an unexpected value was encountered. */ export function assertUnreachable(x: never): never { throw new Error( `Didn't expect to get here. Unexpected value: ${JSON.stringify(x)}`, ); } /** @link https://stackoverflow.com/a/69413184 */ export const assertType = () => {}; export type Unpacked = T extends (infer U)[] ? U : T extends (...args: unknown[]) => infer U ? U : T extends Promise ? U : T; export type Nullish = T | null | undefined; export type Unwrapped any> = Unpacked< Awaited> >; export type UnwrappedNonNullable any> = NonNullable< Unwrapped >;