blob: e973e1629075a91f0935c04557eeb7c56cd96aea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
export type NotNull<T> = T extends null ? never : T;
export type Nullable<T> = T | null;
function isNotNull<T>(input: Nullable<T>): input is NotNull<T> {
return input !== null;
}
function expectNotNull<T>(input: Nullable<T>, msg: string): NotNull<T> {
if (isNotNull(input)) {
return input;
}
throw new TypeError(msg);
}
export function unwrapNullable<T>(input: Nullable<T>): NotNull<T> {
return expectNotNull(input, `unwrapping \`null\``);
}
|