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) • 759 B
TypeScript
export type NotNullOrUndefined<T> = T extends null | undefined ? never : T;
export type Maybe<T> = T | null | undefined;
export declare function isNotNullOrUndefined<T>(input: Maybe<T>): input is NotNullOrUndefined<T>;
export declare function isNullOrUndefined<T>(input: Maybe<T>): input is null | undefined;
/**
* Return _input_ as `T` if the passed _input_ is not `null` and `undefined`.
* Otherwise, throw `TypeError` with the passed `msg`.
*/
export declare function expectNotNullOrUndefined<T>(input: Maybe<T>, msg: string): NotNullOrUndefined<T>;
/**
* Return _value_ as `T` if the passed _value_ is not `null` and `undefined`.
* Otherwise, throw `TypeError`.
*/
export declare function unwrapMaybe<T>(value: Maybe<T>): NotNullOrUndefined<T>;