export type NotNull = T extends null ? never : T; export type Nullable = T | null; function isNotNull(input: Nullable): input is NotNull { return input !== null; } function expectNotNull(input: Nullable, msg: string): NotNull { if (isNotNull(input)) { return input; } throw new TypeError(msg); } export function unwrapNullable(input: Nullable): NotNull { return expectNotNull(input, `unwrapping \`null\``); }