@sinclair/typebox 0.34.0 → 0.34.2
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.
- package/build/cjs/syntax/runtime.d.ts +4 -1
- package/build/cjs/syntax/runtime.js +3 -1
- package/build/cjs/syntax/static.d.ts +3 -3
- package/build/cjs/type/array/array.d.ts +1 -1
- package/build/cjs/type/awaited/awaited.d.ts +8 -3
- package/build/cjs/type/awaited/awaited.js +20 -20
- package/build/cjs/type/computed/computed.d.ts +9 -0
- package/build/cjs/type/computed/computed.js +10 -0
- package/build/cjs/type/computed/index.d.ts +1 -0
- package/build/cjs/type/computed/index.js +18 -0
- package/build/cjs/type/guard/kind.d.ts +9 -4
- package/build/cjs/type/guard/kind.js +10 -0
- package/build/cjs/type/guard/type.d.ts +6 -3
- package/build/cjs/type/guard/type.js +6 -0
- package/build/cjs/type/indexed/indexed-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/indexed/indexed-from-mapped-key.js +10 -10
- package/build/cjs/type/indexed/indexed-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/indexed/indexed-from-mapped-result.js +11 -10
- package/build/cjs/type/indexed/indexed-property-keys.d.ts +6 -6
- package/build/cjs/type/indexed/indexed-property-keys.js +14 -14
- package/build/cjs/type/indexed/indexed.d.ts +34 -20
- package/build/cjs/type/indexed/indexed.js +59 -46
- package/build/cjs/type/intersect/intersect-evaluated.d.ts +6 -6
- package/build/cjs/type/intersect/intersect-evaluated.js +16 -16
- package/build/cjs/type/intersect/intersect.d.ts +2 -2
- package/build/cjs/type/intersect/intersect.js +6 -6
- package/build/cjs/type/keyof/keyof-from-mapped-result.d.ts +6 -6
- package/build/cjs/type/keyof/keyof-from-mapped-result.js +10 -10
- package/build/cjs/type/keyof/keyof-property-keys.d.ts +7 -7
- package/build/cjs/type/keyof/keyof-property-keys.js +22 -22
- package/build/cjs/type/keyof/keyof.d.ts +11 -6
- package/build/cjs/type/keyof/keyof.js +22 -13
- package/build/cjs/type/module/compute.d.ts +54 -0
- package/build/cjs/type/module/compute.js +154 -0
- package/build/cjs/type/module/infer.d.ts +43 -0
- package/build/cjs/type/module/infer.js +3 -0
- package/build/cjs/type/module/module.d.ts +8 -52
- package/build/cjs/type/module/module.js +14 -11
- package/build/cjs/type/not/not.d.ts +1 -1
- package/build/cjs/type/not/not.js +2 -2
- package/build/cjs/type/omit/omit-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/omit/omit-from-mapped-key.js +10 -12
- package/build/cjs/type/omit/omit-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/omit/omit-from-mapped-result.js +10 -10
- package/build/cjs/type/omit/omit.d.ts +26 -14
- package/build/cjs/type/omit/omit.js +46 -35
- package/build/cjs/type/partial/partial.d.ts +11 -7
- package/build/cjs/type/partial/partial.js +36 -24
- package/build/cjs/type/pick/pick-from-mapped-key.d.ts +6 -6
- package/build/cjs/type/pick/pick-from-mapped-key.js +10 -10
- package/build/cjs/type/pick/pick-from-mapped-result.d.ts +5 -5
- package/build/cjs/type/pick/pick-from-mapped-result.js +10 -10
- package/build/cjs/type/pick/pick.d.ts +25 -15
- package/build/cjs/type/pick/pick.js +47 -36
- package/build/cjs/type/record/record.d.ts +4 -2
- package/build/cjs/type/record/record.js +31 -28
- package/build/cjs/type/required/required.d.ts +12 -8
- package/build/cjs/type/required/required.js +37 -25
- package/build/cjs/type/tuple/tuple.d.ts +1 -1
- package/build/cjs/type/tuple/tuple.js +4 -4
- package/build/cjs/type/type/javascript.d.ts +10 -10
- package/build/cjs/type/type/javascript.js +6 -6
- package/build/cjs/type/type/json.d.ts +41 -51
- package/build/cjs/type/type/json.js +40 -40
- package/build/cjs/type/union/union-evaluated.d.ts +6 -6
- package/build/cjs/type/union/union-evaluated.js +11 -10
- package/build/cjs/type/union/union.d.ts +1 -1
- package/build/cjs/type/union/union.js +4 -4
- package/build/cjs/value/check/check.js +3 -3
- package/build/cjs/value/transform/decode.js +7 -7
- package/build/cjs/value/transform/encode.js +7 -7
- package/build/cjs/value/transform/has.js +18 -18
- package/build/esm/syntax/runtime.d.mts +4 -1
- package/build/esm/syntax/runtime.mjs +3 -1
- package/build/esm/syntax/static.d.mts +3 -3
- package/build/esm/type/array/array.d.mts +1 -1
- package/build/esm/type/awaited/awaited.d.mts +8 -3
- package/build/esm/type/awaited/awaited.mjs +20 -20
- package/build/esm/type/computed/computed.d.mts +9 -0
- package/build/esm/type/computed/computed.mjs +6 -0
- package/build/esm/type/computed/index.d.mts +1 -0
- package/build/esm/type/computed/index.mjs +1 -0
- package/build/esm/type/guard/kind.d.mts +9 -4
- package/build/esm/type/guard/kind.mjs +8 -0
- package/build/esm/type/guard/type.d.mts +6 -3
- package/build/esm/type/guard/type.mjs +5 -0
- package/build/esm/type/indexed/indexed-from-mapped-key.d.mts +6 -6
- package/build/esm/type/indexed/indexed-from-mapped-key.mjs +10 -10
- package/build/esm/type/indexed/indexed-from-mapped-result.d.mts +5 -5
- package/build/esm/type/indexed/indexed-from-mapped-result.mjs +11 -10
- package/build/esm/type/indexed/indexed-property-keys.d.mts +6 -6
- package/build/esm/type/indexed/indexed-property-keys.mjs +14 -14
- package/build/esm/type/indexed/indexed.d.mts +34 -20
- package/build/esm/type/indexed/indexed.mjs +55 -42
- package/build/esm/type/intersect/intersect-evaluated.d.mts +6 -6
- package/build/esm/type/intersect/intersect-evaluated.mjs +16 -16
- package/build/esm/type/intersect/intersect.d.mts +2 -2
- package/build/esm/type/intersect/intersect.mjs +6 -6
- package/build/esm/type/keyof/keyof-from-mapped-result.d.mts +6 -6
- package/build/esm/type/keyof/keyof-from-mapped-result.mjs +10 -10
- package/build/esm/type/keyof/keyof-property-keys.d.mts +7 -7
- package/build/esm/type/keyof/keyof-property-keys.mjs +22 -22
- package/build/esm/type/keyof/keyof.d.mts +11 -6
- package/build/esm/type/keyof/keyof.mjs +22 -13
- package/build/esm/type/module/compute.d.mts +54 -0
- package/build/esm/type/module/compute.mjs +148 -0
- package/build/esm/type/module/infer.d.mts +43 -0
- package/build/esm/type/module/infer.mjs +1 -0
- package/build/esm/type/module/module.d.mts +8 -52
- package/build/esm/type/module/module.mjs +14 -11
- package/build/esm/type/not/not.d.mts +1 -1
- package/build/esm/type/not/not.mjs +2 -2
- package/build/esm/type/omit/omit-from-mapped-key.d.mts +6 -6
- package/build/esm/type/omit/omit-from-mapped-key.mjs +10 -12
- package/build/esm/type/omit/omit-from-mapped-result.d.mts +5 -5
- package/build/esm/type/omit/omit-from-mapped-result.mjs +10 -10
- package/build/esm/type/omit/omit.d.mts +26 -14
- package/build/esm/type/omit/omit.mjs +43 -32
- package/build/esm/type/partial/partial.d.mts +11 -7
- package/build/esm/type/partial/partial.mjs +29 -17
- package/build/esm/type/pick/pick-from-mapped-key.d.mts +6 -6
- package/build/esm/type/pick/pick-from-mapped-key.mjs +10 -10
- package/build/esm/type/pick/pick-from-mapped-result.d.mts +5 -5
- package/build/esm/type/pick/pick-from-mapped-result.mjs +10 -10
- package/build/esm/type/pick/pick.d.mts +25 -15
- package/build/esm/type/pick/pick.mjs +43 -32
- package/build/esm/type/record/record.d.mts +4 -2
- package/build/esm/type/record/record.mjs +15 -12
- package/build/esm/type/required/required.d.mts +12 -8
- package/build/esm/type/required/required.mjs +33 -21
- package/build/esm/type/tuple/tuple.d.mts +1 -1
- package/build/esm/type/tuple/tuple.mjs +4 -4
- package/build/esm/type/type/javascript.d.mts +10 -10
- package/build/esm/type/type/javascript.mjs +6 -6
- package/build/esm/type/type/json.d.mts +41 -51
- package/build/esm/type/type/json.mjs +40 -40
- package/build/esm/type/union/union-evaluated.d.mts +6 -6
- package/build/esm/type/union/union-evaluated.mjs +11 -10
- package/build/esm/type/union/union.d.mts +1 -1
- package/build/esm/type/union/union.mjs +4 -4
- package/build/esm/value/check/check.mjs +2 -2
- package/build/esm/value/transform/decode.mjs +2 -2
- package/build/esm/value/transform/encode.mjs +2 -2
- package/build/esm/value/transform/has.mjs +2 -2
- package/package.json +1 -1
- package/readme.md +30 -19
|
@@ -1,48 +1,60 @@
|
|
|
1
1
|
import { CreateType } from '../create/type.mjs';
|
|
2
|
+
import { Computed } from '../computed/index.mjs';
|
|
3
|
+
import { Object } from '../object/index.mjs';
|
|
2
4
|
import { Intersect } from '../intersect/index.mjs';
|
|
3
5
|
import { Union } from '../union/index.mjs';
|
|
4
|
-
import {
|
|
6
|
+
import { Ref } from '../ref/index.mjs';
|
|
5
7
|
import { OptionalKind, TransformKind } from '../symbols/index.mjs';
|
|
6
8
|
import { Discard } from '../discard/index.mjs';
|
|
7
9
|
import { RequiredFromMappedResult } from './required-from-mapped-result.mjs';
|
|
8
10
|
// ------------------------------------------------------------------
|
|
9
11
|
// TypeGuard
|
|
10
12
|
// ------------------------------------------------------------------
|
|
11
|
-
import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/kind.mjs';
|
|
13
|
+
import { IsMappedResult, IsIntersect, IsUnion, IsObject, IsRef, IsComputed } from '../guard/kind.mjs';
|
|
14
|
+
// prettier-ignore
|
|
15
|
+
function FromComputed(target, parameters) {
|
|
16
|
+
return Computed('Required', [Computed(target, parameters)]);
|
|
17
|
+
}
|
|
12
18
|
// prettier-ignore
|
|
13
|
-
function
|
|
14
|
-
return
|
|
19
|
+
function FromRef($ref) {
|
|
20
|
+
return Computed('Required', [Ref($ref)]);
|
|
15
21
|
}
|
|
16
22
|
// prettier-ignore
|
|
17
|
-
function FromProperties(
|
|
18
|
-
const
|
|
19
|
-
for (const K of globalThis.Object.getOwnPropertyNames(
|
|
20
|
-
|
|
21
|
-
return
|
|
23
|
+
function FromProperties(properties) {
|
|
24
|
+
const requiredProperties = {};
|
|
25
|
+
for (const K of globalThis.Object.getOwnPropertyNames(properties))
|
|
26
|
+
requiredProperties[K] = Discard(properties[K], [OptionalKind]);
|
|
27
|
+
return requiredProperties;
|
|
22
28
|
}
|
|
23
29
|
// prettier-ignore
|
|
24
|
-
function FromObject(
|
|
25
|
-
const options = Discard(
|
|
26
|
-
const properties = FromProperties(
|
|
30
|
+
function FromObject(type) {
|
|
31
|
+
const options = Discard(type, [TransformKind, '$id', 'required', 'properties']);
|
|
32
|
+
const properties = FromProperties(type['properties']);
|
|
27
33
|
return Object(properties, options);
|
|
28
34
|
}
|
|
35
|
+
// prettier-ignore
|
|
36
|
+
function FromRest(types) {
|
|
37
|
+
return types.map(type => RequiredResolve(type));
|
|
38
|
+
}
|
|
29
39
|
// ------------------------------------------------------------------
|
|
30
40
|
// RequiredResolve
|
|
31
41
|
// ------------------------------------------------------------------
|
|
32
42
|
// prettier-ignore
|
|
33
|
-
function RequiredResolve(
|
|
34
|
-
return (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
function RequiredResolve(type) {
|
|
44
|
+
return (IsComputed(type) ? FromComputed(type.target, type.parameters) :
|
|
45
|
+
IsRef(type) ? FromRef(type.$ref) :
|
|
46
|
+
IsIntersect(type) ? Intersect(FromRest(type.allOf)) :
|
|
47
|
+
IsUnion(type) ? Union(FromRest(type.anyOf)) :
|
|
48
|
+
IsObject(type) ? FromObject(type) :
|
|
49
|
+
Object({}));
|
|
38
50
|
}
|
|
39
51
|
/** `[Json]` Constructs a type where all properties are required */
|
|
40
|
-
export function Required(
|
|
41
|
-
if (IsMappedResult(
|
|
42
|
-
return RequiredFromMappedResult(
|
|
52
|
+
export function Required(type, options) {
|
|
53
|
+
if (IsMappedResult(type)) {
|
|
54
|
+
return RequiredFromMappedResult(type, options);
|
|
43
55
|
}
|
|
44
56
|
else {
|
|
45
57
|
// special: mapping types require overridable options
|
|
46
|
-
return CreateType({ ...RequiredResolve(
|
|
58
|
+
return CreateType({ ...RequiredResolve(type), ...options });
|
|
47
59
|
}
|
|
48
60
|
}
|
|
@@ -12,5 +12,5 @@ export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
|
12
12
|
maxItems: number;
|
|
13
13
|
}
|
|
14
14
|
/** `[Json]` Creates a Tuple type */
|
|
15
|
-
export declare function Tuple<
|
|
15
|
+
export declare function Tuple<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): TTuple<Types>;
|
|
16
16
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
import { Kind } from '../symbols/index.mjs';
|
|
3
3
|
/** `[Json]` Creates a Tuple type */
|
|
4
|
-
export function Tuple(
|
|
4
|
+
export function Tuple(types, options) {
|
|
5
5
|
// prettier-ignore
|
|
6
|
-
return CreateType(
|
|
7
|
-
{ [Kind]: 'Tuple', type: 'array', items, additionalItems: false, minItems:
|
|
8
|
-
{ [Kind]: 'Tuple', type: 'array', minItems:
|
|
6
|
+
return CreateType(types.length > 0 ?
|
|
7
|
+
{ [Kind]: 'Tuple', type: 'array', items: types, additionalItems: false, minItems: types.length, maxItems: types.length } :
|
|
8
|
+
{ [Kind]: 'Tuple', type: 'array', minItems: types.length, maxItems: types.length }, options);
|
|
9
9
|
}
|
|
@@ -20,33 +20,33 @@ import { type TVoid } from '../void/index.mjs';
|
|
|
20
20
|
/** JavaScript Type Builder with Static Resolution for TypeScript */
|
|
21
21
|
export declare class JavaScriptTypeBuilder extends JsonTypeBuilder {
|
|
22
22
|
/** `[JavaScript]` Creates a AsyncIterator type */
|
|
23
|
-
AsyncIterator<
|
|
23
|
+
AsyncIterator<Type extends TSchema>(items: Type, options?: SchemaOptions): TAsyncIterator<Type>;
|
|
24
24
|
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
25
|
-
Awaited<
|
|
25
|
+
Awaited<Type extends TSchema>(schema: Type, options?: SchemaOptions): TAwaited<Type>;
|
|
26
26
|
/** `[JavaScript]` Creates a BigInt type */
|
|
27
27
|
BigInt(options?: BigIntOptions): TBigInt;
|
|
28
28
|
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
29
|
-
ConstructorParameters<
|
|
29
|
+
ConstructorParameters<Type extends TConstructor>(schema: Type, options?: SchemaOptions): TConstructorParameters<Type>;
|
|
30
30
|
/** `[JavaScript]` Creates a Constructor type */
|
|
31
|
-
Constructor<
|
|
31
|
+
Constructor<Parameters extends TSchema[], InstanceType extends TSchema>(parameters: [...Parameters], instanceType: InstanceType, options?: SchemaOptions): TConstructor<Parameters, InstanceType>;
|
|
32
32
|
/** `[JavaScript]` Creates a Date type */
|
|
33
33
|
Date(options?: DateOptions): TDate;
|
|
34
34
|
/** `[JavaScript]` Creates a Function type */
|
|
35
|
-
Function<
|
|
35
|
+
Function<Parameters extends TSchema[], ReturnType extends TSchema>(parameters: [...Parameters], returnType: ReturnType, options?: SchemaOptions): TFunction<Parameters, ReturnType>;
|
|
36
36
|
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
37
|
-
InstanceType<
|
|
37
|
+
InstanceType<Type extends TConstructor>(schema: Type, options?: SchemaOptions): TInstanceType<Type>;
|
|
38
38
|
/** `[JavaScript]` Creates an Iterator type */
|
|
39
|
-
Iterator<
|
|
39
|
+
Iterator<Type extends TSchema>(items: Type, options?: SchemaOptions): TIterator<Type>;
|
|
40
40
|
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
41
|
-
Parameters<
|
|
41
|
+
Parameters<Type extends TFunction>(schema: Type, options?: SchemaOptions): TParameters<Type>;
|
|
42
42
|
/** `[JavaScript]` Creates a Promise type */
|
|
43
|
-
Promise<
|
|
43
|
+
Promise<Type extends TSchema>(item: Type, options?: SchemaOptions): TPromise<Type>;
|
|
44
44
|
/** `[JavaScript]` Creates a RegExp type */
|
|
45
45
|
RegExp(pattern: string, options?: RegExpOptions): TRegExp;
|
|
46
46
|
/** `[JavaScript]` Creates a RegExp type */
|
|
47
47
|
RegExp(regex: RegExp, options?: RegExpOptions): TRegExp;
|
|
48
48
|
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
49
|
-
ReturnType<
|
|
49
|
+
ReturnType<Type extends TFunction>(type: Type, options?: SchemaOptions): TReturnType<Type>;
|
|
50
50
|
/** `[JavaScript]` Creates a Symbol type */
|
|
51
51
|
Symbol(options?: SchemaOptions): TSymbol;
|
|
52
52
|
/** `[JavaScript]` Creates a Undefined type */
|
|
@@ -35,16 +35,16 @@ export class JavaScriptTypeBuilder extends JsonTypeBuilder {
|
|
|
35
35
|
return ConstructorParameters(schema, options);
|
|
36
36
|
}
|
|
37
37
|
/** `[JavaScript]` Creates a Constructor type */
|
|
38
|
-
Constructor(parameters,
|
|
39
|
-
return Constructor(parameters,
|
|
38
|
+
Constructor(parameters, instanceType, options) {
|
|
39
|
+
return Constructor(parameters, instanceType, options);
|
|
40
40
|
}
|
|
41
41
|
/** `[JavaScript]` Creates a Date type */
|
|
42
42
|
Date(options = {}) {
|
|
43
43
|
return Date(options);
|
|
44
44
|
}
|
|
45
45
|
/** `[JavaScript]` Creates a Function type */
|
|
46
|
-
Function(parameters,
|
|
47
|
-
return FunctionType(parameters,
|
|
46
|
+
Function(parameters, returnType, options) {
|
|
47
|
+
return FunctionType(parameters, returnType, options);
|
|
48
48
|
}
|
|
49
49
|
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
50
50
|
InstanceType(schema, options) {
|
|
@@ -67,8 +67,8 @@ export class JavaScriptTypeBuilder extends JsonTypeBuilder {
|
|
|
67
67
|
return RegExp(unresolved, options);
|
|
68
68
|
}
|
|
69
69
|
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
70
|
-
ReturnType(
|
|
71
|
-
return ReturnType(
|
|
70
|
+
ReturnType(type, options) {
|
|
71
|
+
return ReturnType(type, options);
|
|
72
72
|
}
|
|
73
73
|
/** `[JavaScript]` Creates a Symbol type */
|
|
74
74
|
Symbol(options) {
|
|
@@ -7,11 +7,11 @@ import { type TEnum, type TEnumKey, type TEnumValue } from '../enum/index.mjs';
|
|
|
7
7
|
import { type TExclude, type TExcludeFromMappedResult, type TExcludeFromTemplateLiteral } from '../exclude/index.mjs';
|
|
8
8
|
import { type TExtends, type TExtendsFromMappedKey, type TExtendsFromMappedResult } from '../extends/index.mjs';
|
|
9
9
|
import { type TExtract, type TExtractFromMappedResult, type TExtractFromTemplateLiteral } from '../extract/index.mjs';
|
|
10
|
-
import { TIndex, type TIndexPropertyKeys
|
|
10
|
+
import { TIndex, type TIndexPropertyKeys } from '../indexed/index.mjs';
|
|
11
11
|
import { type IntegerOptions, type TInteger } from '../integer/index.mjs';
|
|
12
12
|
import { Intersect, type IntersectOptions } from '../intersect/index.mjs';
|
|
13
13
|
import { type TCapitalize, type TUncapitalize, type TLowercase, type TUppercase } from '../intrinsic/index.mjs';
|
|
14
|
-
import { type TKeyOf
|
|
14
|
+
import { type TKeyOf } from '../keyof/index.mjs';
|
|
15
15
|
import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
|
|
16
16
|
import { type TMappedFunction, type TMapped, type TMappedResult } from '../mapped/index.mjs';
|
|
17
17
|
import { type TNever } from '../never/index.mjs';
|
|
@@ -21,10 +21,10 @@ import { type TMappedKey } from '../mapped/index.mjs';
|
|
|
21
21
|
import { TModule } from '../module/index.mjs';
|
|
22
22
|
import { type TNumber, type NumberOptions } from '../number/index.mjs';
|
|
23
23
|
import { type TObject, type TProperties, type ObjectOptions } from '../object/index.mjs';
|
|
24
|
-
import { type TOmit
|
|
24
|
+
import { type TOmit } from '../omit/index.mjs';
|
|
25
25
|
import { type TOptionalWithFlag, type TOptionalFromMappedResult } from '../optional/index.mjs';
|
|
26
26
|
import { type TPartial, type TPartialFromMappedResult } from '../partial/index.mjs';
|
|
27
|
-
import { type TPick
|
|
27
|
+
import { type TPick } from '../pick/index.mjs';
|
|
28
28
|
import { type TReadonlyWithFlag, type TReadonlyFromMappedResult } from '../readonly/index.mjs';
|
|
29
29
|
import { type TReadonlyOptional } from '../readonly-optional/index.mjs';
|
|
30
30
|
import { type TRecordOrObject } from '../record/index.mjs';
|
|
@@ -43,27 +43,27 @@ import { type TUnsafe, type UnsafeOptions } from '../unsafe/index.mjs';
|
|
|
43
43
|
/** Json Type Builder with Static Resolution for TypeScript */
|
|
44
44
|
export declare class JsonTypeBuilder {
|
|
45
45
|
/** `[Json]` Creates a Readonly and Optional property */
|
|
46
|
-
ReadonlyOptional<
|
|
46
|
+
ReadonlyOptional<Type extends TSchema>(type: Type): TReadonlyOptional<Type>;
|
|
47
47
|
/** `[Json]` Creates a Readonly property */
|
|
48
|
-
Readonly<
|
|
48
|
+
Readonly<Type extends TMappedResult, Flag extends boolean>(type: Type, enable: Flag): TReadonlyFromMappedResult<Type, Flag>;
|
|
49
49
|
/** `[Json]` Creates a Readonly property */
|
|
50
|
-
Readonly<
|
|
50
|
+
Readonly<Type extends TSchema, Flag extends boolean>(type: Type, enable: Flag): TReadonlyWithFlag<Type, Flag>;
|
|
51
51
|
/** `[Json]` Creates a Optional property */
|
|
52
|
-
Readonly<
|
|
52
|
+
Readonly<Type extends TMappedResult>(type: Type): TReadonlyFromMappedResult<Type, true>;
|
|
53
53
|
/** `[Json]` Creates a Readonly property */
|
|
54
|
-
Readonly<
|
|
54
|
+
Readonly<Type extends TSchema>(type: Type): TReadonlyWithFlag<Type, true>;
|
|
55
55
|
/** `[Json]` Creates a Optional property */
|
|
56
|
-
Optional<
|
|
56
|
+
Optional<Type extends TMappedResult, Flag extends boolean>(type: Type, enable: Flag): TOptionalFromMappedResult<Type, Flag>;
|
|
57
57
|
/** `[Json]` Creates a Optional property */
|
|
58
|
-
Optional<
|
|
58
|
+
Optional<Type extends TSchema, Flag extends boolean>(type: Type, enable: Flag): TOptionalWithFlag<Type, Flag>;
|
|
59
59
|
/** `[Json]` Creates a Optional property */
|
|
60
|
-
Optional<
|
|
60
|
+
Optional<Type extends TMappedResult>(type: Type): TOptionalFromMappedResult<Type, true>;
|
|
61
61
|
/** `[Json]` Creates a Optional property */
|
|
62
|
-
Optional<
|
|
62
|
+
Optional<Type extends TSchema>(type: Type): TOptionalWithFlag<Type, true>;
|
|
63
63
|
/** `[Json]` Creates an Any type */
|
|
64
64
|
Any(options?: SchemaOptions): TAny;
|
|
65
65
|
/** `[Json]` Creates an Array type */
|
|
66
|
-
Array<
|
|
66
|
+
Array<Type extends TSchema>(items: Type, options?: ArrayOptions): TArray<Type>;
|
|
67
67
|
/** `[Json]` Creates a Boolean type */
|
|
68
68
|
Boolean(options?: SchemaOptions): TBoolean;
|
|
69
69
|
/** `[Json]` Intrinsic function to Capitalize LiteralString types */
|
|
@@ -93,25 +93,23 @@ export declare class JsonTypeBuilder {
|
|
|
93
93
|
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
94
94
|
Extract<L extends TSchema, R extends TSchema>(type: L, union: R, options?: SchemaOptions): TExtract<L, R>;
|
|
95
95
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
96
|
-
Index<
|
|
96
|
+
Index<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, key: readonly [...PropertyKeys], options?: SchemaOptions): TIndex<Type, PropertyKeys>;
|
|
97
97
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
98
|
-
Index<
|
|
98
|
+
Index<Type extends TSchema, Key extends TMappedKey>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
|
|
99
99
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
100
|
-
Index<
|
|
100
|
+
Index<Type extends TSchema, Key extends TMappedResult>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
|
|
101
101
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
102
|
-
Index<
|
|
102
|
+
Index<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
|
|
103
103
|
/** `[Json]` Creates an Integer type */
|
|
104
104
|
Integer(options?: IntegerOptions): TInteger;
|
|
105
105
|
/** `[Json]` Creates an Intersect type */
|
|
106
|
-
Intersect<
|
|
106
|
+
Intersect<Types extends TSchema[]>(types: [...Types], options?: IntersectOptions): Intersect<Types>;
|
|
107
107
|
/** `[Json]` Creates a KeyOf type */
|
|
108
|
-
KeyOf<
|
|
109
|
-
/** `[Json]` Creates a KeyOf type */
|
|
110
|
-
KeyOf<T extends TSchema>(schema: T, options?: SchemaOptions): TKeyOf<T>;
|
|
108
|
+
KeyOf<Type extends TSchema>(type: Type, options?: SchemaOptions): TKeyOf<Type>;
|
|
111
109
|
/** `[Json]` Creates a Literal type */
|
|
112
|
-
Literal<
|
|
110
|
+
Literal<LiteralValue extends TLiteralValue>(literalValue: LiteralValue, options?: SchemaOptions): TLiteral<LiteralValue>;
|
|
113
111
|
/** `[Json]` Intrinsic function to Lowercase LiteralString types */
|
|
114
|
-
Lowercase<
|
|
112
|
+
Lowercase<Type extends TSchema>(type: Type, options?: SchemaOptions): TLowercase<Type>;
|
|
115
113
|
/** `[Json]` Creates a Mapped object type */
|
|
116
114
|
Mapped<K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>, F extends TMappedFunction<I> = TMappedFunction<I>, R extends TMapped<I, F> = TMapped<I, F>>(key: K, map: F, options?: ObjectOptions): R;
|
|
117
115
|
/** `[Json]` Creates a Mapped object type */
|
|
@@ -121,59 +119,51 @@ export declare class JsonTypeBuilder {
|
|
|
121
119
|
/** `[Json]` Creates a Never type */
|
|
122
120
|
Never(options?: SchemaOptions): TNever;
|
|
123
121
|
/** `[Json]` Creates a Not type */
|
|
124
|
-
Not<T extends TSchema>(
|
|
122
|
+
Not<T extends TSchema>(type: T, options?: SchemaOptions): TNot<T>;
|
|
125
123
|
/** `[Json]` Creates a Null type */
|
|
126
124
|
Null(options?: SchemaOptions): TNull;
|
|
127
125
|
/** `[Json]` Creates a Number type */
|
|
128
126
|
Number(options?: NumberOptions): TNumber;
|
|
129
127
|
/** `[Json]` Creates an Object type */
|
|
130
128
|
Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
|
|
131
|
-
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
132
|
-
Omit<T extends TMappedResult, K extends PropertyKey[]>(T: T, K: [...K], options?: SchemaOptions): TOmitFromMappedResult<T, K>;
|
|
133
|
-
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
134
|
-
Omit<T extends TSchema, K extends TMappedKey>(T: T, K: K, options?: SchemaOptions): TOmitFromMappedKey<T, K>;
|
|
135
|
-
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
136
|
-
Omit<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TOmit<T, I>;
|
|
137
|
-
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
138
|
-
Omit<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TOmit<T, K>;
|
|
139
|
-
/** `[Json]` Constructs a type where all properties are optional */
|
|
140
|
-
Partial<T extends TMappedResult>(T: T, options?: SchemaOptions): TPartialFromMappedResult<T>;
|
|
141
|
-
/** `[Json]` Constructs a type where all properties are optional */
|
|
142
|
-
Partial<T extends TSchema>(schema: T, options?: SchemaOptions): TPartial<T>;
|
|
143
129
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
144
|
-
|
|
130
|
+
Omit<Type extends TSchema, Key extends PropertyKey[]>(type: Type, key: readonly [...Key], options?: SchemaOptions): TOmit<Type, Key>;
|
|
145
131
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
146
|
-
|
|
132
|
+
Omit<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TOmit<Type, Key>;
|
|
133
|
+
/** `[Json]` Constructs a type where all properties are optional */
|
|
134
|
+
Partial<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TPartialFromMappedResult<MappedResult>;
|
|
135
|
+
/** `[Json]` Constructs a type where all properties are optional */
|
|
136
|
+
Partial<Type extends TSchema>(type: Type, options?: SchemaOptions): TPartial<Type>;
|
|
147
137
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
148
|
-
Pick<
|
|
138
|
+
Pick<Type extends TSchema, Key extends PropertyKey[]>(type: Type, key: readonly [...Key], options?: SchemaOptions): TPick<Type, Key>;
|
|
149
139
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
150
|
-
Pick<
|
|
140
|
+
Pick<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TPick<Type, Key>;
|
|
151
141
|
/** `[Json]` Creates a Record type */
|
|
152
|
-
Record<
|
|
142
|
+
Record<Key extends TSchema, Value extends TSchema>(key: Key, value: Value, options?: ObjectOptions): TRecordOrObject<Key, Value>;
|
|
153
143
|
/** `[Json]` Creates a Recursive type */
|
|
154
144
|
Recursive<T extends TSchema>(callback: (thisType: TThis) => T, options?: SchemaOptions): TRecursive<T>;
|
|
155
145
|
/** `[Json]` Creates a Ref type. */
|
|
156
146
|
Ref<Ref extends string>($ref: Ref, options?: SchemaOptions): TRef<Ref>;
|
|
157
147
|
/** `[Json]` Constructs a type where all properties are required */
|
|
158
|
-
Required<
|
|
148
|
+
Required<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TRequiredFromMappedResult<MappedResult>;
|
|
159
149
|
/** `[Json]` Constructs a type where all properties are required */
|
|
160
|
-
Required<
|
|
150
|
+
Required<Type extends TSchema>(type: Type, options?: SchemaOptions): TRequired<Type>;
|
|
161
151
|
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
162
|
-
Rest<
|
|
152
|
+
Rest<Type extends TSchema>(type: Type): TRest<Type>;
|
|
163
153
|
/** `[Json]` Creates a String type */
|
|
164
154
|
String(options?: StringOptions): TString;
|
|
165
155
|
/** `[Json]` Creates a TemplateLiteral type from template dsl string */
|
|
166
|
-
TemplateLiteral<
|
|
156
|
+
TemplateLiteral<Syntax extends string>(syntax: Syntax, options?: SchemaOptions): TTemplateLiteralSyntax<Syntax>;
|
|
167
157
|
/** `[Json]` Creates a TemplateLiteral type */
|
|
168
|
-
TemplateLiteral<
|
|
158
|
+
TemplateLiteral<Kinds extends TTemplateLiteralKind[]>(kinds: [...Kinds], options?: SchemaOptions): TTemplateLiteral<Kinds>;
|
|
169
159
|
/** `[Json]` Creates a Transform type */
|
|
170
|
-
Transform<
|
|
160
|
+
Transform<Type extends TSchema>(type: Type): TransformDecodeBuilder<Type>;
|
|
171
161
|
/** `[Json]` Creates a Tuple type */
|
|
172
|
-
Tuple<
|
|
162
|
+
Tuple<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): TTuple<Types>;
|
|
173
163
|
/** `[Json]` Intrinsic function to Uncapitalize LiteralString types */
|
|
174
|
-
Uncapitalize<
|
|
164
|
+
Uncapitalize<Type extends TSchema>(type: Type, options?: SchemaOptions): TUncapitalize<Type>;
|
|
175
165
|
/** `[Json]` Creates a Union type */
|
|
176
|
-
Union<
|
|
166
|
+
Union<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): Union<Types>;
|
|
177
167
|
/** `[Json]` Creates an Unknown type */
|
|
178
168
|
Unknown(options?: SchemaOptions): TUnknown;
|
|
179
169
|
/** `[Json]` Creates a Unsafe type that will infers as the generic argument T */
|
|
@@ -44,16 +44,16 @@ export class JsonTypeBuilder {
|
|
|
44
44
|
// Modifiers
|
|
45
45
|
// ------------------------------------------------------------------------
|
|
46
46
|
/** `[Json]` Creates a Readonly and Optional property */
|
|
47
|
-
ReadonlyOptional(
|
|
48
|
-
return ReadonlyOptional(
|
|
47
|
+
ReadonlyOptional(type) {
|
|
48
|
+
return ReadonlyOptional(type);
|
|
49
49
|
}
|
|
50
50
|
/** `[Json]` Creates a Readonly property */
|
|
51
|
-
Readonly(
|
|
52
|
-
return Readonly(
|
|
51
|
+
Readonly(type, enable) {
|
|
52
|
+
return Readonly(type, enable ?? true);
|
|
53
53
|
}
|
|
54
54
|
/** `[Json]` Creates a Optional property */
|
|
55
|
-
Optional(
|
|
56
|
-
return Optional(
|
|
55
|
+
Optional(type, enable) {
|
|
56
|
+
return Optional(type, enable ?? true);
|
|
57
57
|
}
|
|
58
58
|
// ------------------------------------------------------------------------
|
|
59
59
|
// Types
|
|
@@ -63,8 +63,8 @@ export class JsonTypeBuilder {
|
|
|
63
63
|
return Any(options);
|
|
64
64
|
}
|
|
65
65
|
/** `[Json]` Creates an Array type */
|
|
66
|
-
Array(
|
|
67
|
-
return Array(
|
|
66
|
+
Array(items, options) {
|
|
67
|
+
return Array(items, options);
|
|
68
68
|
}
|
|
69
69
|
/** `[Json]` Creates a Boolean type */
|
|
70
70
|
Boolean(options) {
|
|
@@ -99,28 +99,28 @@ export class JsonTypeBuilder {
|
|
|
99
99
|
return Extract(type, union, options);
|
|
100
100
|
}
|
|
101
101
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
102
|
-
Index(
|
|
103
|
-
return Index(
|
|
102
|
+
Index(type, key, options) {
|
|
103
|
+
return Index(type, key, options);
|
|
104
104
|
}
|
|
105
105
|
/** `[Json]` Creates an Integer type */
|
|
106
106
|
Integer(options) {
|
|
107
107
|
return Integer(options);
|
|
108
108
|
}
|
|
109
109
|
/** `[Json]` Creates an Intersect type */
|
|
110
|
-
Intersect(
|
|
111
|
-
return Intersect(
|
|
110
|
+
Intersect(types, options) {
|
|
111
|
+
return Intersect(types, options);
|
|
112
112
|
}
|
|
113
113
|
/** `[Json]` Creates a KeyOf type */
|
|
114
|
-
KeyOf(
|
|
115
|
-
return KeyOf(
|
|
114
|
+
KeyOf(type, options) {
|
|
115
|
+
return KeyOf(type, options);
|
|
116
116
|
}
|
|
117
117
|
/** `[Json]` Creates a Literal type */
|
|
118
|
-
Literal(
|
|
119
|
-
return Literal(
|
|
118
|
+
Literal(literalValue, options) {
|
|
119
|
+
return Literal(literalValue, options);
|
|
120
120
|
}
|
|
121
121
|
/** `[Json]` Intrinsic function to Lowercase LiteralString types */
|
|
122
|
-
Lowercase(
|
|
123
|
-
return Lowercase(
|
|
122
|
+
Lowercase(type, options) {
|
|
123
|
+
return Lowercase(type, options);
|
|
124
124
|
}
|
|
125
125
|
/** `[Json]` Creates a Mapped object type */
|
|
126
126
|
Mapped(key, map, options) {
|
|
@@ -135,8 +135,8 @@ export class JsonTypeBuilder {
|
|
|
135
135
|
return Never(options);
|
|
136
136
|
}
|
|
137
137
|
/** `[Json]` Creates a Not type */
|
|
138
|
-
Not(
|
|
139
|
-
return Not(
|
|
138
|
+
Not(type, options) {
|
|
139
|
+
return Not(type, options);
|
|
140
140
|
}
|
|
141
141
|
/** `[Json]` Creates a Null type */
|
|
142
142
|
Null(options) {
|
|
@@ -151,20 +151,20 @@ export class JsonTypeBuilder {
|
|
|
151
151
|
return Object(properties, options);
|
|
152
152
|
}
|
|
153
153
|
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
154
|
-
Omit(schema,
|
|
155
|
-
return Omit(schema,
|
|
154
|
+
Omit(schema, selector, options) {
|
|
155
|
+
return Omit(schema, selector, options);
|
|
156
156
|
}
|
|
157
157
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
158
|
-
Partial(
|
|
159
|
-
return Partial(
|
|
158
|
+
Partial(type, options) {
|
|
159
|
+
return Partial(type, options);
|
|
160
160
|
}
|
|
161
161
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
162
|
-
Pick(
|
|
163
|
-
return Pick(
|
|
162
|
+
Pick(type, key, options) {
|
|
163
|
+
return Pick(type, key, options);
|
|
164
164
|
}
|
|
165
165
|
/** `[Json]` Creates a Record type */
|
|
166
|
-
Record(key,
|
|
167
|
-
return Record(key,
|
|
166
|
+
Record(key, value, options) {
|
|
167
|
+
return Record(key, value, options);
|
|
168
168
|
}
|
|
169
169
|
/** `[Json]` Creates a Recursive type */
|
|
170
170
|
Recursive(callback, options) {
|
|
@@ -175,12 +175,12 @@ export class JsonTypeBuilder {
|
|
|
175
175
|
return Ref($ref, options);
|
|
176
176
|
}
|
|
177
177
|
/** `[Json]` Constructs a type where all properties are required */
|
|
178
|
-
Required(
|
|
179
|
-
return Required(
|
|
178
|
+
Required(type, options) {
|
|
179
|
+
return Required(type, options);
|
|
180
180
|
}
|
|
181
181
|
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
182
|
-
Rest(
|
|
183
|
-
return Rest(
|
|
182
|
+
Rest(type) {
|
|
183
|
+
return Rest(type);
|
|
184
184
|
}
|
|
185
185
|
/** `[Json]` Creates a String type */
|
|
186
186
|
String(options) {
|
|
@@ -191,20 +191,20 @@ export class JsonTypeBuilder {
|
|
|
191
191
|
return TemplateLiteral(unresolved, options);
|
|
192
192
|
}
|
|
193
193
|
/** `[Json]` Creates a Transform type */
|
|
194
|
-
Transform(
|
|
195
|
-
return Transform(
|
|
194
|
+
Transform(type) {
|
|
195
|
+
return Transform(type);
|
|
196
196
|
}
|
|
197
197
|
/** `[Json]` Creates a Tuple type */
|
|
198
|
-
Tuple(
|
|
199
|
-
return Tuple(
|
|
198
|
+
Tuple(types, options) {
|
|
199
|
+
return Tuple(types, options);
|
|
200
200
|
}
|
|
201
201
|
/** `[Json]` Intrinsic function to Uncapitalize LiteralString types */
|
|
202
|
-
Uncapitalize(
|
|
203
|
-
return Uncapitalize(
|
|
202
|
+
Uncapitalize(type, options) {
|
|
203
|
+
return Uncapitalize(type, options);
|
|
204
204
|
}
|
|
205
205
|
/** `[Json]` Creates a Union type */
|
|
206
|
-
Union(
|
|
207
|
-
return Union(
|
|
206
|
+
Union(types, options) {
|
|
207
|
+
return Union(types, options);
|
|
208
208
|
}
|
|
209
209
|
/** `[Json]` Creates an Unknown type */
|
|
210
210
|
Unknown(options) {
|
|
@@ -3,11 +3,11 @@ import { type TNever } from '../never/index.mjs';
|
|
|
3
3
|
import { type TOptional } from '../optional/index.mjs';
|
|
4
4
|
import type { TReadonly } from '../readonly/index.mjs';
|
|
5
5
|
import type { TUnion } from './union-type.mjs';
|
|
6
|
-
type TIsUnionOptional<
|
|
7
|
-
type TRemoveOptionalFromRest<
|
|
8
|
-
type TRemoveOptionalFromType<
|
|
9
|
-
type TResolveUnion<
|
|
10
|
-
export type TUnionEvaluated<
|
|
6
|
+
type TIsUnionOptional<Types extends TSchema[]> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TOptional<TSchema> ? true : TIsUnionOptional<Right> : false);
|
|
7
|
+
type TRemoveOptionalFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TOptional<infer S extends TSchema> ? TRemoveOptionalFromRest<Right, [...Result, TRemoveOptionalFromType<S>]> : TRemoveOptionalFromRest<Right, [...Result, Left]> : Result);
|
|
8
|
+
type TRemoveOptionalFromType<Type extends TSchema> = (Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TRemoveOptionalFromType<Type>> : Type extends TOptional<infer Type extends TSchema> ? TRemoveOptionalFromType<Type> : Type);
|
|
9
|
+
type TResolveUnion<Types extends TSchema[], Result extends TSchema[] = TRemoveOptionalFromRest<Types>, IsOptional extends boolean = TIsUnionOptional<Types>> = (IsOptional extends true ? TOptional<TUnion<Result>> : TUnion<Result>);
|
|
10
|
+
export type TUnionEvaluated<Types extends TSchema[]> = (Types extends [TSchema] ? Types[0] : Types extends [] ? TNever : TResolveUnion<Types>);
|
|
11
11
|
/** `[Json]` Creates an evaluated Union type */
|
|
12
|
-
export declare function UnionEvaluated<
|
|
12
|
+
export declare function UnionEvaluated<Types extends TSchema[], Result = TUnionEvaluated<Types>>(T: [...Types], options?: SchemaOptions): Result;
|
|
13
13
|
export {};
|
|
@@ -9,27 +9,28 @@ import { UnionCreate } from './union-create.mjs';
|
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
import { IsOptional } from '../guard/kind.mjs';
|
|
11
11
|
// prettier-ignore
|
|
12
|
-
function IsUnionOptional(
|
|
13
|
-
return
|
|
12
|
+
function IsUnionOptional(types) {
|
|
13
|
+
return types.some(type => IsOptional(type));
|
|
14
14
|
}
|
|
15
15
|
// prettier-ignore
|
|
16
|
-
function RemoveOptionalFromRest(
|
|
17
|
-
return
|
|
16
|
+
function RemoveOptionalFromRest(types) {
|
|
17
|
+
return types.map(left => IsOptional(left) ? RemoveOptionalFromType(left) : left);
|
|
18
18
|
}
|
|
19
19
|
// prettier-ignore
|
|
20
20
|
function RemoveOptionalFromType(T) {
|
|
21
21
|
return (Discard(T, [OptionalKind]));
|
|
22
22
|
}
|
|
23
23
|
// prettier-ignore
|
|
24
|
-
function ResolveUnion(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
function ResolveUnion(types, options) {
|
|
25
|
+
const isOptional = IsUnionOptional(types);
|
|
26
|
+
return (isOptional
|
|
27
|
+
? Optional(UnionCreate(RemoveOptionalFromRest(types), options))
|
|
28
|
+
: UnionCreate(RemoveOptionalFromRest(types), options));
|
|
28
29
|
}
|
|
29
30
|
/** `[Json]` Creates an evaluated Union type */
|
|
30
31
|
export function UnionEvaluated(T, options) {
|
|
31
32
|
// prettier-ignore
|
|
32
|
-
return (T.length ===
|
|
33
|
-
T.length ===
|
|
33
|
+
return (T.length === 1 ? CreateType(T[0], options) :
|
|
34
|
+
T.length === 0 ? Never(options) :
|
|
34
35
|
ResolveUnion(T, options));
|
|
35
36
|
}
|
|
@@ -3,4 +3,4 @@ import { type TNever } from '../never/index.mjs';
|
|
|
3
3
|
import type { TUnion } from './union-type.mjs';
|
|
4
4
|
export type Union<T extends TSchema[]> = (T extends [] ? TNever : T extends [TSchema] ? T[0] : TUnion<T>);
|
|
5
5
|
/** `[Json]` Creates a Union type */
|
|
6
|
-
export declare function Union<
|
|
6
|
+
export declare function Union<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): Union<Types>;
|
|
@@ -2,9 +2,9 @@ import { Never } from '../never/index.mjs';
|
|
|
2
2
|
import { CreateType } from '../create/type.mjs';
|
|
3
3
|
import { UnionCreate } from './union-create.mjs';
|
|
4
4
|
/** `[Json]` Creates a Union type */
|
|
5
|
-
export function Union(
|
|
5
|
+
export function Union(types, options) {
|
|
6
6
|
// prettier-ignore
|
|
7
|
-
return (
|
|
8
|
-
|
|
9
|
-
UnionCreate(
|
|
7
|
+
return (types.length === 0 ? Never(options) :
|
|
8
|
+
types.length === 1 ? CreateType(types[0], options) :
|
|
9
|
+
UnionCreate(types, options));
|
|
10
10
|
}
|