UNPKG

1.23 kBTypeScriptView Raw
1import { IType, IAnyType, ExtractCSTWithSTN } from "../../internal";
2/** @hidden */
3export declare type ValidOptionalValue = string | boolean | number | null | undefined;
4/** @hidden */
5export declare type ValidOptionalValues = [ValidOptionalValue, ...ValidOptionalValue[]];
6/** @hidden */
7export declare type OptionalDefaultValueOrFunction<IT extends IAnyType> = IT["CreationType"] | IT["SnapshotType"] | (() => ExtractCSTWithSTN<IT>);
8/** @hidden */
9export interface IOptionalIType<IT extends IAnyType, OptionalVals extends ValidOptionalValues> extends IType<IT["CreationType"] | OptionalVals[number], IT["SnapshotType"], IT["TypeWithoutSTN"]> {
10}
11export declare function optional<IT extends IAnyType>(type: IT, defaultValueOrFunction: OptionalDefaultValueOrFunction<IT>): IOptionalIType<IT, [undefined]>;
12export declare function optional<IT extends IAnyType, OptionalVals extends ValidOptionalValues>(type: IT, defaultValueOrFunction: OptionalDefaultValueOrFunction<IT>, optionalValues: OptionalVals): IOptionalIType<IT, OptionalVals>;
13/**
14 * Returns if a value represents an optional type.
15 *
16 * @template IT
17 * @param type
18 * @returns
19 */
20export declare function isOptionalType<IT extends IAnyType>(type: IT): type is IT;
21
\No newline at end of file