anki/tslib/src/tsutils.ts

15 lines
373 B
TypeScript
Raw Normal View History

/** 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.");
}
}