UNPKG

typedash

Version:

modern, type-safe collection of utility functions

1 lines 912 B
{"version":3,"file":"assertNever-EOgaGI1R.cjs","names":[],"sources":["../src/functions/assertNever/assertNever.ts"],"sourcesContent":["/**\n * Throws an error if a value is of type `never`.\n * Used for exhaustive checks.\n * @param inclusive The value to check.\n * @param noThrow If `true`, returns `undefined` instead of throwing an error.\n * @returns This function never returns a value, but throws an error if `inclusive` is of type `never`.\n * @example\n * ```typescript\n * assertNever('foo' as never); // throws an error\n * assertNever('foo' as never, true); // returns undefined\n * ```\n */\nexport function assertNever(inclusive: never, noThrow = false): never {\n if (noThrow) {\n return undefined as never;\n }\n\n throw new Error(`Unexpected inclusive value: ${inclusive}`);\n}\n"],"mappings":";;;;;;;;;;;;;;AAYA,SAAgB,YAAY,WAAkB,UAAU,OAAc;AACpE,KAAI,QACF;AAGF,OAAM,IAAI,MAAM,+BAA+B,YAAY"}