UNPKG

typed-utilities

Version:
32 lines (31 loc) 1.09 kB
import { Either, Left, Right } from "./Either"; export declare type Option<T> = Either<T, null>; export declare type Some<T> = Left<T>; export declare type None = Right<null>; declare function isSome<T>(option: Option<T>): option is Some<T>; declare function assertSome<T>(option: Option<T>, message?: string): asserts option is Some<T>; declare function isNone(option: Option<unknown>): option is None; declare function assertNone(option: Option<unknown>, message?: string): asserts option is None; declare type Match<T, IfSome, IfNone> = { readonly some: (value: T) => IfSome; readonly none: () => IfNone; }; export declare const Option: { is: { some: typeof isSome; none: typeof isNone; }; assert: { some: typeof assertSome; none: typeof assertNone; }; of: { some: <T>(value: T) => Some<T>; none: () => None; }; to: { someValue: <T_1>(option: Some<T_1>) => T_1; }; match: <T_2, IfSome, IfNone>(option: Option<T_2>, match: Match<T_2, IfSome, IfNone>) => IfSome | IfNone; }; export {};