@hazae41/option
Version:
Rust-like Option for TypeScript
20 lines (17 loc) • 646 B
TypeScript
import { NoneInit, None } from './none.js';
import { SomeInit, Some } from './some.js';
type Nullable<T> = T | undefined | null;
type Optional<T> = T | undefined;
type NonOptional<T> = Exclude<T, undefined>;
type OptionInit<T> = SomeInit<T> | NoneInit;
type Option<T> = Some<T> | None;
declare namespace Option {
function from<T>(init: OptionInit<T>): Option<T>;
/**
* Create an Option from a nullable value
* @param inner
* @returns `Some<T>` if `T`, `None` if `undefined`
*/
function wrap<T>(inner: Nullable<T>): Option<T>;
}
export { type NonOptional, type Nullable, Option, type OptionInit, type Optional };