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) • 710 B
TypeScript
export type NotUndefined<T> = T extends undefined ? never : T;
export type Undefinable<T> = T | undefined;
export declare function isNotUndefined<T>(input: Undefinable<T>): input is NotUndefined<T>;
export declare function isUndefined<T>(input: Undefinable<T>): input is undefined;
/**
* Return _input_ as `T` if the passed _input_ is not `undefined`.
* Otherwise, throw `TypeError` with the passed `msg`.
*/
export declare function expectNotUndefined<T>(input: Undefinable<T>, msg: string): NotUndefined<T>;
/**
* Return _input_ as `T` if the passed _input_ is not `undefined`.
* Otherwise, throw `TypeError`.
*/
export declare function unwrapUndefinable<T>(input: Undefinable<T>): NotUndefined<T>;