mobx-state-tree
Version:
Opinionated, transactional, MobX powered state container
21 lines (20 loc) • 1.23 kB
TypeScript
import { IType, IAnyType, ExtractCSTWithSTN } from "../../internal";
/** @hidden */
export type ValidOptionalValue = string | boolean | number | null | undefined;
/** @hidden */
export type ValidOptionalValues = [ValidOptionalValue, ...ValidOptionalValue[]];
/** @hidden */
export type OptionalDefaultValueOrFunction<IT extends IAnyType> = IT["CreationType"] | IT["SnapshotType"] | (() => ExtractCSTWithSTN<IT>);
/** @hidden */
export interface IOptionalIType<IT extends IAnyType, OptionalVals extends ValidOptionalValues> extends IType<IT["CreationType"] | OptionalVals[number], IT["SnapshotType"], IT["TypeWithoutSTN"]> {
}
export declare function optional<IT extends IAnyType>(type: IT, defaultValueOrFunction: OptionalDefaultValueOrFunction<IT>): IOptionalIType<IT, [undefined]>;
export declare function optional<IT extends IAnyType, OptionalVals extends ValidOptionalValues>(type: IT, defaultValueOrFunction: OptionalDefaultValueOrFunction<IT>, optionalValues: OptionalVals): IOptionalIType<IT, OptionalVals>;
/**
* Returns if a value represents an optional type.
*
* @template IT
* @param type
* @returns
*/
export declare function isOptionalType(type: unknown): type is IOptionalIType<IAnyType, [any, ...any[]]>;