mobx-state-tree 3.12.2 → 3.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +103 -23
  2. package/dist/core/action.d.ts +50 -48
  3. package/dist/core/actionContext.d.ts +27 -0
  4. package/dist/core/flow.d.ts +14 -30
  5. package/dist/core/json-patch.d.ts +36 -36
  6. package/dist/core/mst-operations.d.ts +451 -444
  7. package/dist/core/node/BaseNode.d.ts +1 -1
  8. package/dist/core/node/Hook.d.ts +17 -1
  9. package/dist/core/node/create-node.d.ts +1 -1
  10. package/dist/core/node/identifier-cache.d.ts +1 -1
  11. package/dist/core/node/livelinessChecking.d.ts +37 -37
  12. package/dist/core/node/node-utils.d.ts +28 -28
  13. package/dist/core/node/object-node.d.ts +1 -1
  14. package/dist/core/node/scalar-node.d.ts +1 -1
  15. package/dist/core/process.d.ts +45 -45
  16. package/dist/core/type/type-checker.d.ts +30 -30
  17. package/dist/core/type/type.d.ts +162 -177
  18. package/dist/index.d.ts +3 -3
  19. package/dist/internal.d.ts +37 -35
  20. package/dist/middlewares/create-action-tracking-middleware.d.ts +24 -22
  21. package/dist/middlewares/createActionTrackingMiddleware2.d.ts +34 -0
  22. package/dist/middlewares/on-action.d.ts +87 -79
  23. package/dist/mobx-state-tree.js +6285 -5985
  24. package/dist/mobx-state-tree.min.js +16 -1
  25. package/dist/mobx-state-tree.module.js +6234 -5938
  26. package/dist/mobx-state-tree.umd.js +6263 -5985
  27. package/dist/mobx-state-tree.umd.min.js +16 -1
  28. package/dist/types/complex-types/array.d.ts +52 -51
  29. package/dist/types/complex-types/map.d.ts +80 -79
  30. package/dist/types/complex-types/model.d.ts +133 -125
  31. package/dist/types/index.d.ts +29 -29
  32. package/dist/types/primitives.d.ts +81 -81
  33. package/dist/types/utility-types/custom.d.ts +60 -60
  34. package/dist/types/utility-types/enumeration.d.ts +5 -5
  35. package/dist/types/utility-types/frozen.d.ts +11 -11
  36. package/dist/types/utility-types/identifier.d.ts +44 -44
  37. package/dist/types/utility-types/late.d.ts +10 -10
  38. package/dist/types/utility-types/literal.d.ts +25 -25
  39. package/dist/types/utility-types/maybe.d.ts +26 -26
  40. package/dist/types/utility-types/optional.d.ts +20 -20
  41. package/dist/types/utility-types/reference.d.ts +41 -47
  42. package/dist/types/utility-types/refinement.d.ts +10 -10
  43. package/dist/types/utility-types/snapshotProcessor.d.ts +61 -61
  44. package/dist/types/utility-types/union.d.ts +55 -55
  45. package/dist/utils.d.ts +4 -4
  46. package/package.json +16 -12
@@ -1,81 +1,81 @@
1
- import { ISimpleType, IType } from "../internal";
2
- /**
3
- * `types.string` - Creates a type that can only contain a string value.
4
- * This type is used for string values by default
5
- *
6
- * Example:
7
- * ```ts
8
- * const Person = types.model({
9
- * firstName: types.string,
10
- * lastName: "Doe"
11
- * })
12
- * ```
13
- */
14
- export declare const string: ISimpleType<string>;
15
- /**
16
- * `types.number` - Creates a type that can only contain a numeric value.
17
- * This type is used for numeric values by default
18
- *
19
- * Example:
20
- * ```ts
21
- * const Vector = types.model({
22
- * x: types.number,
23
- * y: 1.5
24
- * })
25
- * ```
26
- */
27
- export declare const number: ISimpleType<number>;
28
- /**
29
- * `types.integer` - Creates a type that can only contain an integer value.
30
- * This type is used for integer values by default
31
- *
32
- * Example:
33
- * ```ts
34
- * const Size = types.model({
35
- * width: types.integer,
36
- * height: 10
37
- * })
38
- * ```
39
- */
40
- export declare const integer: ISimpleType<number>;
41
- /**
42
- * `types.boolean` - Creates a type that can only contain a boolean value.
43
- * This type is used for boolean values by default
44
- *
45
- * Example:
46
- * ```ts
47
- * const Thing = types.model({
48
- * isCool: types.boolean,
49
- * isAwesome: false
50
- * })
51
- * ```
52
- */
53
- export declare const boolean: ISimpleType<boolean>;
54
- /**
55
- * `types.null` - The type of the value `null`
56
- */
57
- export declare const nullType: ISimpleType<null>;
58
- /**
59
- * `types.undefined` - The type of the value `undefined`
60
- */
61
- export declare const undefinedType: ISimpleType<undefined>;
62
- /**
63
- * `types.Date` - Creates a type that can only contain a javascript Date value.
64
- *
65
- * Example:
66
- * ```ts
67
- * const LogLine = types.model({
68
- * timestamp: types.Date,
69
- * })
70
- *
71
- * LogLine.create({ timestamp: new Date() })
72
- * ```
73
- */
74
- export declare const DatePrimitive: IType<number | Date, number, Date>;
75
- /**
76
- * Returns if a given value represents a primitive type.
77
- *
78
- * @param type
79
- * @returns
80
- */
81
- export declare function isPrimitiveType<IT extends ISimpleType<string> | ISimpleType<number> | ISimpleType<boolean> | typeof DatePrimitive>(type: IT): type is IT;
1
+ import { ISimpleType, IType } from "../internal";
2
+ /**
3
+ * `types.string` - Creates a type that can only contain a string value.
4
+ * This type is used for string values by default
5
+ *
6
+ * Example:
7
+ * ```ts
8
+ * const Person = types.model({
9
+ * firstName: types.string,
10
+ * lastName: "Doe"
11
+ * })
12
+ * ```
13
+ */
14
+ export declare const string: ISimpleType<string>;
15
+ /**
16
+ * `types.number` - Creates a type that can only contain a numeric value.
17
+ * This type is used for numeric values by default
18
+ *
19
+ * Example:
20
+ * ```ts
21
+ * const Vector = types.model({
22
+ * x: types.number,
23
+ * y: 1.5
24
+ * })
25
+ * ```
26
+ */
27
+ export declare const number: ISimpleType<number>;
28
+ /**
29
+ * `types.integer` - Creates a type that can only contain an integer value.
30
+ * This type is used for integer values by default
31
+ *
32
+ * Example:
33
+ * ```ts
34
+ * const Size = types.model({
35
+ * width: types.integer,
36
+ * height: 10
37
+ * })
38
+ * ```
39
+ */
40
+ export declare const integer: ISimpleType<number>;
41
+ /**
42
+ * `types.boolean` - Creates a type that can only contain a boolean value.
43
+ * This type is used for boolean values by default
44
+ *
45
+ * Example:
46
+ * ```ts
47
+ * const Thing = types.model({
48
+ * isCool: types.boolean,
49
+ * isAwesome: false
50
+ * })
51
+ * ```
52
+ */
53
+ export declare const boolean: ISimpleType<boolean>;
54
+ /**
55
+ * `types.null` - The type of the value `null`
56
+ */
57
+ export declare const nullType: ISimpleType<null>;
58
+ /**
59
+ * `types.undefined` - The type of the value `undefined`
60
+ */
61
+ export declare const undefinedType: ISimpleType<undefined>;
62
+ /**
63
+ * `types.Date` - Creates a type that can only contain a javascript Date value.
64
+ *
65
+ * Example:
66
+ * ```ts
67
+ * const LogLine = types.model({
68
+ * timestamp: types.Date,
69
+ * })
70
+ *
71
+ * LogLine.create({ timestamp: new Date() })
72
+ * ```
73
+ */
74
+ export declare const DatePrimitive: IType<number | Date, number, Date>;
75
+ /**
76
+ * Returns if a given value represents a primitive type.
77
+ *
78
+ * @param type
79
+ * @returns
80
+ */
81
+ export declare function isPrimitiveType<IT extends ISimpleType<string> | ISimpleType<number> | ISimpleType<boolean> | typeof DatePrimitive>(type: IT): type is IT;
@@ -1,60 +1,60 @@
1
- import { IType } from "../../internal";
2
- export interface CustomTypeOptions<S, T> {
3
- /** Friendly name */
4
- name: string;
5
- /** given a serialized value, how to turn it into the target type */
6
- fromSnapshot(snapshot: S): T;
7
- /** return the serialization of the current value */
8
- toSnapshot(value: T): S;
9
- /** if true, this is a converted value, if false, it's a snapshot */
10
- isTargetType(value: T | S): boolean;
11
- /** a non empty string is assumed to be a validation error */
12
- getValidationMessage(snapshot: S): string;
13
- }
14
- /**
15
- * `types.custom` - Creates a custom type. Custom types can be used for arbitrary immutable values, that have a serializable representation. For example, to create your own Date representation, Decimal type etc.
16
- *
17
- * The signature of the options is:
18
- * ```ts
19
- * export interface CustomTypeOptions<S, T> {
20
- * // Friendly name
21
- * name: string
22
- * // given a serialized value, how to turn it into the target type
23
- * fromSnapshot(snapshot: S): T
24
- * // return the serialization of the current value
25
- * toSnapshot(value: T): S
26
- * // if true, this is a converted value, if false, it's a snapshot
27
- * isTargetType(value: T | S): value is T
28
- * // a non empty string is assumed to be a validation error
29
- * getValidationMessage?(snapshot: S): string
30
- * }
31
- * ```
32
- *
33
- * Example:
34
- * ```ts
35
- * const DecimalPrimitive = types.custom<string, Decimal>({
36
- * name: "Decimal",
37
- * fromSnapshot(value: string) {
38
- * return new Decimal(value)
39
- * },
40
- * toSnapshot(value: Decimal) {
41
- * return value.toString()
42
- * },
43
- * isTargetType(value: string | Decimal): boolean {
44
- * return value instanceof Decimal
45
- * },
46
- * getValidationMessage(value: string): string {
47
- * if (/^-?\d+\.\d+$/.test(value)) return "" // OK
48
- * return `'${value}' doesn't look like a valid decimal number`
49
- * }
50
- * })
51
- *
52
- * const Wallet = types.model({
53
- * balance: DecimalPrimitive
54
- * })
55
- * ```
56
- *
57
- * @param options
58
- * @returns
59
- */
60
- export declare function custom<S, T>(options: CustomTypeOptions<S, T>): IType<S | T, S, T>;
1
+ import { IType } from "../../internal";
2
+ export interface CustomTypeOptions<S, T> {
3
+ /** Friendly name */
4
+ name: string;
5
+ /** given a serialized value, how to turn it into the target type */
6
+ fromSnapshot(snapshot: S): T;
7
+ /** return the serialization of the current value */
8
+ toSnapshot(value: T): S;
9
+ /** if true, this is a converted value, if false, it's a snapshot */
10
+ isTargetType(value: T | S): boolean;
11
+ /** a non empty string is assumed to be a validation error */
12
+ getValidationMessage(snapshot: S): string;
13
+ }
14
+ /**
15
+ * `types.custom` - Creates a custom type. Custom types can be used for arbitrary immutable values, that have a serializable representation. For example, to create your own Date representation, Decimal type etc.
16
+ *
17
+ * The signature of the options is:
18
+ * ```ts
19
+ * export interface CustomTypeOptions<S, T> {
20
+ * // Friendly name
21
+ * name: string
22
+ * // given a serialized value, how to turn it into the target type
23
+ * fromSnapshot(snapshot: S): T
24
+ * // return the serialization of the current value
25
+ * toSnapshot(value: T): S
26
+ * // if true, this is a converted value, if false, it's a snapshot
27
+ * isTargetType(value: T | S): value is T
28
+ * // a non empty string is assumed to be a validation error
29
+ * getValidationMessage?(snapshot: S): string
30
+ * }
31
+ * ```
32
+ *
33
+ * Example:
34
+ * ```ts
35
+ * const DecimalPrimitive = types.custom<string, Decimal>({
36
+ * name: "Decimal",
37
+ * fromSnapshot(value: string) {
38
+ * return new Decimal(value)
39
+ * },
40
+ * toSnapshot(value: Decimal) {
41
+ * return value.toString()
42
+ * },
43
+ * isTargetType(value: string | Decimal): boolean {
44
+ * return value instanceof Decimal
45
+ * },
46
+ * getValidationMessage(value: string): string {
47
+ * if (/^-?\d+\.\d+$/.test(value)) return "" // OK
48
+ * return `'${value}' doesn't look like a valid decimal number`
49
+ * }
50
+ * })
51
+ *
52
+ * const Wallet = types.model({
53
+ * balance: DecimalPrimitive
54
+ * })
55
+ * ```
56
+ *
57
+ * @param options
58
+ * @returns
59
+ */
60
+ export declare function custom<S, T>(options: CustomTypeOptions<S, T>): IType<S | T, S, T>;
@@ -1,5 +1,5 @@
1
- import { ISimpleType } from "../../internal";
2
- /** @hidden */
3
- export declare type UnionStringArray<T extends string[]> = T[number];
4
- export declare function enumeration<T extends string>(options: T[]): ISimpleType<UnionStringArray<T[]>>;
5
- export declare function enumeration<T extends string>(name: string, options: T[]): ISimpleType<UnionStringArray<T[]>>;
1
+ import { ISimpleType } from "../../internal";
2
+ /** @hidden */
3
+ export declare type UnionStringArray<T extends string[]> = T[number];
4
+ export declare function enumeration<T extends string>(options: T[]): ISimpleType<UnionStringArray<T[]>>;
5
+ export declare function enumeration<T extends string>(name: string, options: T[]): ISimpleType<UnionStringArray<T[]>>;
@@ -1,11 +1,11 @@
1
- import { IType } from "../../internal";
2
- export declare function frozen<C>(subType: IType<C, any, any>): IType<C, C, C>;
3
- export declare function frozen<T>(defaultValue: T): IType<T | undefined | null, T, T>;
4
- export declare function frozen<T = any>(): IType<T, T, T>;
5
- /**
6
- * Returns if a given value represents a frozen type.
7
- *
8
- * @param type
9
- * @returns
10
- */
11
- export declare function isFrozenType<IT extends IType<T | any, T, T>, T = any>(type: IT): type is IT;
1
+ import { IType } from "../../internal";
2
+ export declare function frozen<C>(subType: IType<C, any, any>): IType<C, C, C>;
3
+ export declare function frozen<T>(defaultValue: T): IType<T | undefined | null, T, T>;
4
+ export declare function frozen<T = any>(): IType<T, T, T>;
5
+ /**
6
+ * Returns if a given value represents a frozen type.
7
+ *
8
+ * @param type
9
+ * @returns
10
+ */
11
+ export declare function isFrozenType<IT extends IType<T | any, T, T>, T = any>(type: IT): type is IT;
@@ -1,44 +1,44 @@
1
- import { ISimpleType } from "../../internal";
2
- /**
3
- * `types.identifier` - Identifiers are used to make references, lifecycle events and reconciling works.
4
- * Inside a state tree, for each type can exist only one instance for each given identifier.
5
- * For example there couldn't be 2 instances of user with id 1. If you need more, consider using references.
6
- * Identifier can be used only as type property of a model.
7
- * This type accepts as parameter the value type of the identifier field that can be either string or number.
8
- *
9
- * Example:
10
- * ```ts
11
- * const Todo = types.model("Todo", {
12
- * id: types.identifier,
13
- * title: types.string
14
- * })
15
- * ```
16
- *
17
- * @returns
18
- */
19
- export declare const identifier: ISimpleType<string>;
20
- /**
21
- * `types.identifierNumber` - Similar to `types.identifier`. This one will serialize from / to a number when applying snapshots
22
- *
23
- * Example:
24
- * ```ts
25
- * const Todo = types.model("Todo", {
26
- * id: types.identifierNumber,
27
- * title: types.string
28
- * })
29
- * ```
30
- *
31
- * @returns
32
- */
33
- export declare const identifierNumber: ISimpleType<number>;
34
- /**
35
- * Returns if a given value represents an identifier type.
36
- *
37
- * @param type
38
- * @returns
39
- */
40
- export declare function isIdentifierType<IT extends typeof identifier | typeof identifierNumber>(type: IT): type is IT;
41
- /**
42
- * Valid types for identifiers.
43
- */
44
- export declare type ReferenceIdentifier = string | number;
1
+ import { ISimpleType } from "../../internal";
2
+ /**
3
+ * `types.identifier` - Identifiers are used to make references, lifecycle events and reconciling works.
4
+ * Inside a state tree, for each type can exist only one instance for each given identifier.
5
+ * For example there couldn't be 2 instances of user with id 1. If you need more, consider using references.
6
+ * Identifier can be used only as type property of a model.
7
+ * This type accepts as parameter the value type of the identifier field that can be either string or number.
8
+ *
9
+ * Example:
10
+ * ```ts
11
+ * const Todo = types.model("Todo", {
12
+ * id: types.identifier,
13
+ * title: types.string
14
+ * })
15
+ * ```
16
+ *
17
+ * @returns
18
+ */
19
+ export declare const identifier: ISimpleType<string>;
20
+ /**
21
+ * `types.identifierNumber` - Similar to `types.identifier`. This one will serialize from / to a number when applying snapshots
22
+ *
23
+ * Example:
24
+ * ```ts
25
+ * const Todo = types.model("Todo", {
26
+ * id: types.identifierNumber,
27
+ * title: types.string
28
+ * })
29
+ * ```
30
+ *
31
+ * @returns
32
+ */
33
+ export declare const identifierNumber: ISimpleType<number>;
34
+ /**
35
+ * Returns if a given value represents an identifier type.
36
+ *
37
+ * @param type
38
+ * @returns
39
+ */
40
+ export declare function isIdentifierType<IT extends typeof identifier | typeof identifierNumber>(type: IT): type is IT;
41
+ /**
42
+ * Valid types for identifiers.
43
+ */
44
+ export declare type ReferenceIdentifier = string | number;
@@ -1,10 +1,10 @@
1
- import { IAnyType } from "../../internal";
2
- export declare function late<T extends IAnyType>(type: () => T): T;
3
- export declare function late<T extends IAnyType>(name: string, type: () => T): T;
4
- /**
5
- * Returns if a given value represents a late type.
6
- *
7
- * @param type
8
- * @returns
9
- */
10
- export declare function isLateType<IT extends IAnyType>(type: IT): type is IT;
1
+ import { IAnyType } from "../../internal";
2
+ export declare function late<T extends IAnyType>(type: () => T): T;
3
+ export declare function late<T extends IAnyType>(name: string, type: () => T): T;
4
+ /**
5
+ * Returns if a given value represents a late type.
6
+ *
7
+ * @param type
8
+ * @returns
9
+ */
10
+ export declare function isLateType<IT extends IAnyType>(type: IT): type is IT;
@@ -1,25 +1,25 @@
1
- import { ISimpleType, Primitives } from "../../internal";
2
- /**
3
- * `types.literal` - The literal type will return a type that will match only the exact given type.
4
- * The given value must be a primitive, in order to be serialized to a snapshot correctly.
5
- * You can use literal to match exact strings for example the exact male or female string.
6
- *
7
- * Example:
8
- * ```ts
9
- * const Person = types.model({
10
- * name: types.string,
11
- * gender: types.union(types.literal('male'), types.literal('female'))
12
- * })
13
- * ```
14
- *
15
- * @param value The value to use in the strict equal check
16
- * @returns
17
- */
18
- export declare function literal<S extends Primitives>(value: S): ISimpleType<S>;
19
- /**
20
- * Returns if a given value represents a literal type.
21
- *
22
- * @param type
23
- * @returns
24
- */
25
- export declare function isLiteralType<IT extends ISimpleType<any>>(type: IT): type is IT;
1
+ import { ISimpleType, Primitives } from "../../internal";
2
+ /**
3
+ * `types.literal` - The literal type will return a type that will match only the exact given type.
4
+ * The given value must be a primitive, in order to be serialized to a snapshot correctly.
5
+ * You can use literal to match exact strings for example the exact male or female string.
6
+ *
7
+ * Example:
8
+ * ```ts
9
+ * const Person = types.model({
10
+ * name: types.string,
11
+ * gender: types.union(types.literal('male'), types.literal('female'))
12
+ * })
13
+ * ```
14
+ *
15
+ * @param value The value to use in the strict equal check
16
+ * @returns
17
+ */
18
+ export declare function literal<S extends Primitives>(value: S): ISimpleType<S>;
19
+ /**
20
+ * Returns if a given value represents a literal type.
21
+ *
22
+ * @param type
23
+ * @returns
24
+ */
25
+ export declare function isLiteralType<IT extends ISimpleType<any>>(type: IT): type is IT;
@@ -1,26 +1,26 @@
1
- import { IType, IAnyType, ExtractC, ExtractS, ExtractTWithoutSTN } from "../../internal";
2
- /** @hidden */
3
- export interface IMaybeIType<IT extends IAnyType, C, O> extends IType<ExtractC<IT> | C, ExtractS<IT> | O, ExtractTWithoutSTN<IT> | O> {
4
- }
5
- /** @hidden */
6
- export interface IMaybe<IT extends IAnyType> extends IMaybeIType<IT, undefined, undefined> {
7
- }
8
- /** @hidden */
9
- export interface IMaybeNull<IT extends IAnyType> extends IMaybeIType<IT, null | undefined, null> {
10
- }
11
- /**
12
- * `types.maybe` - Maybe will make a type nullable, and also optional.
13
- * The value `undefined` will be used to represent nullability.
14
- *
15
- * @param type
16
- * @returns
17
- */
18
- export declare function maybe<IT extends IAnyType>(type: IT): IMaybe<IT>;
19
- /**
20
- * `types.maybeNull` - Maybe will make a type nullable, and also optional.
21
- * The value `null` will be used to represent no value.
22
- *
23
- * @param type
24
- * @returns
25
- */
26
- export declare function maybeNull<IT extends IAnyType>(type: IT): IMaybeNull<IT>;
1
+ import { IType, IAnyType } from "../../internal";
2
+ /** @hidden */
3
+ export interface IMaybeIType<IT extends IAnyType, C, O> extends IType<IT["CreationType"] | C, IT["SnapshotType"] | O, IT["TypeWithoutSTN"] | O> {
4
+ }
5
+ /** @hidden */
6
+ export interface IMaybe<IT extends IAnyType> extends IMaybeIType<IT, undefined, undefined> {
7
+ }
8
+ /** @hidden */
9
+ export interface IMaybeNull<IT extends IAnyType> extends IMaybeIType<IT, null | undefined, null> {
10
+ }
11
+ /**
12
+ * `types.maybe` - Maybe will make a type nullable, and also optional.
13
+ * The value `undefined` will be used to represent nullability.
14
+ *
15
+ * @param type
16
+ * @returns
17
+ */
18
+ export declare function maybe<IT extends IAnyType>(type: IT): IMaybe<IT>;
19
+ /**
20
+ * `types.maybeNull` - Maybe will make a type nullable, and also optional.
21
+ * The value `null` will be used to represent no value.
22
+ *
23
+ * @param type
24
+ * @returns
25
+ */
26
+ export declare function maybeNull<IT extends IAnyType>(type: IT): IMaybeNull<IT>;
@@ -1,20 +1,20 @@
1
- import { IType, IAnyType, ExtractS, ExtractC, ExtractCSTWithSTN, ExtractTWithoutSTN } from "../../internal";
2
- /** @hidden */
3
- export declare type ValidOptionalValue = string | boolean | number | null | undefined;
4
- /** @hidden */
5
- export declare type ValidOptionalValues = [ValidOptionalValue, ...ValidOptionalValue[]];
6
- /** @hidden */
7
- export declare type OptionalDefaultValueOrFunction<IT extends IAnyType> = ExtractC<IT> | ExtractS<IT> | (() => ExtractCSTWithSTN<IT>);
8
- /** @hidden */
9
- export interface IOptionalIType<IT extends IAnyType, OptionalVals extends ValidOptionalValues> extends IType<ExtractC<IT> | OptionalVals[number], ExtractS<IT>, ExtractTWithoutSTN<IT>> {
10
- }
11
- export declare function optional<IT extends IAnyType>(type: IT, defaultValueOrFunction: OptionalDefaultValueOrFunction<IT>): IOptionalIType<IT, [undefined]>;
12
- export 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
- */
20
- export declare function isOptionalType<IT extends IAnyType>(type: IT): type is IT;
1
+ import { IType, IAnyType, ExtractCSTWithSTN } from "../../internal";
2
+ /** @hidden */
3
+ export declare type ValidOptionalValue = string | boolean | number | null | undefined;
4
+ /** @hidden */
5
+ export declare type ValidOptionalValues = [ValidOptionalValue, ...ValidOptionalValue[]];
6
+ /** @hidden */
7
+ export declare type OptionalDefaultValueOrFunction<IT extends IAnyType> = IT["CreationType"] | IT["SnapshotType"] | (() => ExtractCSTWithSTN<IT>);
8
+ /** @hidden */
9
+ export interface IOptionalIType<IT extends IAnyType, OptionalVals extends ValidOptionalValues> extends IType<IT["CreationType"] | OptionalVals[number], IT["SnapshotType"], IT["TypeWithoutSTN"]> {
10
+ }
11
+ export declare function optional<IT extends IAnyType>(type: IT, defaultValueOrFunction: OptionalDefaultValueOrFunction<IT>): IOptionalIType<IT, [undefined]>;
12
+ export 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
+ */
20
+ export declare function isOptionalType<IT extends IAnyType>(type: IT): type is IT;