export type NotUndefined = T extends undefined ? never : T; export type Undefinable = T | undefined; function isNotUndefined(input: Undefinable): input is NotUndefined { return input !== undefined; } export function expectNotUndefined(input: Undefinable, msg: string): NotUndefined { if (isNotUndefined(input)) { return input; } throw new TypeError(msg); } export function unwrapUndefinable(input: Undefinable): NotUndefined { return expectNotUndefined(input, `unwrapping \`undefined\``); }