option-t
Version:
A toolkit of Nullable/Option/Result type implementation in ECMAScript. Their APIs are inspired by Rust's `Option<T>` and `Result<T, E>`.
15 lines (14 loc) • 632 B
TypeScript
export type NotNull<T> = T extends null ? never : T;
export type Nullable<T> = T | null;
export declare function isNotNull<T>(input: Nullable<T>): input is NotNull<T>;
export declare function isNull<T>(input: Nullable<T>): input is null;
/**
* Return _input_ as `T` if the passed _input_ is not `null`.
* Otherwise, throw `TypeError` with the passed `msg`.
*/
export declare function expectNotNull<T>(input: Nullable<T>, msg: string): NotNull<T>;
/**
* Return _input_ as `T` if the passed _input_ is not `null`.
* Otherwise, throw `TypeError`.
*/
export declare function unwrapNullable<T>(input: Nullable<T>): NotNull<T>;