mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
14 lines
373 B
TypeScript
14 lines
373 B
TypeScript
/** Throws if argument is null/undefined. */
|
|
export function expectNotNull<T>(val: T | null | undefined): T {
|
|
if (val === null || val === undefined) {
|
|
throw Error("Unexpected missing value.");
|
|
}
|
|
return val as T;
|
|
}
|
|
|
|
//* Throws if argument is not truthy. */
|
|
export function assert<T>(val: T): asserts val {
|
|
if (!val) {
|
|
throw Error("Assertion failed.");
|
|
}
|
|
}
|