@saberhq/option-utils
Version:
Utilities for handling optional values in TypeScript.
48 lines • 1.48 kB
TypeScript
/**
* [[include:option-utils/README.md]]
* @module
*/
/**
* Optional type.
*/
export type Maybe<T> = T | null | undefined;
/**
* Applies a function to a list of null/undefined values, unwrapping the null/undefined value or passing it through.
*/
export declare const mapN: <T extends unknown[], U>(fn: (...a: { [K in keyof T]: NonNullable<T[K]>; }) => U, ...args: T) => U | null | undefined;
/**
* Applies a function to a null/undefined inner value if it is null or undefined,
* otherwise returns null/undefined.
*
* For consistency reasons, we recommend just using {@link mapN} in all cases.
*
* @deprecated use {@link mapN}
* @param obj
* @param fn
* @returns
*/
export declare const mapSome: <T, U>(obj: NonNullable<T> | null | undefined, fn: (obj: NonNullable<T>) => U) => U | null | undefined;
/**
* Checks to see if the provided value is not null.
*
* Useful for preserving types in filtering out non-null values.
*
* @param value
* @returns
*/
export declare const isNotNull: <TValue>(value: TValue | null) => value is TValue;
/**
* Checks to see if the provided value is not undefined.
*
* @param value
* @returns
*/
export declare const isNotUndefined: <TValue>(value: TValue | undefined) => value is TValue;
/**
* Checks to see if the provided value is not null or undefined.
*
* @param value
* @returns
*/
export declare const exists: <TValue>(value: TValue | null | undefined) => value is TValue;
//# sourceMappingURL=index.d.ts.map