@sinclair/typebox 0.32.0-dev-26 → 0.32.0-dev-28
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/import/compiler/compiler.mjs +7 -0
- package/build/import/errors/errors.d.mts +16 -15
- package/build/import/errors/errors.mjs +24 -15
- package/build/import/errors/function.mjs +2 -0
- package/build/import/index.d.mts +2 -2
- package/build/import/type/awaited/awaited.mjs +2 -6
- package/build/import/type/clone/value.mjs +6 -2
- package/build/import/type/composite/composite.d.mts +1 -2
- package/build/import/type/composite/composite.mjs +2 -2
- package/build/import/type/const/const.mjs +6 -6
- package/build/import/type/constructor/constructor.d.mts +1 -1
- package/build/import/type/constructor/constructor.mjs +1 -1
- package/build/import/type/deref/deref.mjs +1 -2
- package/build/import/type/discard/discard.mjs +2 -2
- package/build/import/type/enum/enum.mjs +3 -0
- package/build/import/type/exclude/exclude-from-mapped-result.d.mts +5 -5
- package/build/import/type/exclude/exclude-from-mapped-result.mjs +7 -7
- package/build/import/type/exclude/exclude.mjs +0 -1
- package/build/import/type/extends/extends-check.mjs +137 -125
- package/build/import/type/extends/extends-from-mapped-key.d.mts +1 -1
- package/build/import/type/extends/extends-from-mapped-key.mjs +4 -5
- package/build/import/type/extends/extends-from-mapped-result.d.mts +5 -5
- package/build/import/type/extends/extends-from-mapped-result.mjs +7 -7
- package/build/import/type/extends/extends.mjs +0 -1
- package/build/import/type/extract/extract-from-mapped-result.d.mts +5 -5
- package/build/import/type/extract/extract-from-mapped-result.mjs +7 -7
- package/build/import/type/extract/extract.d.mts +1 -2
- package/build/import/type/extract/extract.mjs +4 -2
- package/build/import/type/guard/type.d.mts +3 -0
- package/build/import/type/guard/type.mjs +10 -0
- package/build/import/type/guard/value.d.mts +2 -0
- package/build/import/type/guard/value.mjs +4 -0
- package/build/import/type/index.d.mts +1 -1
- package/build/import/type/index.mjs +1 -1
- package/build/import/type/indexed/indexed-from-mapped-key.d.mts +2 -2
- package/build/import/type/indexed/indexed-from-mapped-key.mjs +4 -5
- package/build/import/type/indexed/indexed-from-mapped-result.d.mts +1 -1
- package/build/import/type/indexed/indexed-property-keys.d.mts +6 -6
- package/build/import/type/indexed/indexed-property-keys.mjs +3 -5
- package/build/import/type/indexed/indexed.d.mts +1 -1
- package/build/import/type/indexed/indexed.mjs +9 -27
- package/build/import/type/intersect/intersect-evaluated.mjs +3 -13
- package/build/import/type/intrinsic/capitalize.d.mts +2 -2
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.d.mts +1 -1
- package/build/import/type/intrinsic/intrinsic-from-mapped-key.mjs +4 -5
- package/build/import/type/intrinsic/intrinsic.d.mts +2 -3
- package/build/import/type/intrinsic/intrinsic.mjs +2 -5
- package/build/import/type/intrinsic/lowercase.d.mts +2 -2
- package/build/import/type/intrinsic/uncapitalize.d.mts +2 -2
- package/build/import/type/intrinsic/uppercase.d.mts +2 -2
- package/build/import/type/iterator/iterator.mjs +1 -1
- package/build/import/type/keyof/keyof-from-mapped-result.d.mts +3 -3
- package/build/import/type/keyof/keyof-from-mapped-result.mjs +4 -4
- package/build/import/type/keyof/keyof-property-keys.d.mts +3 -3
- package/build/import/type/keyof/keyof-property-keys.mjs +9 -15
- package/build/import/type/keyof/keyof.mjs +2 -8
- package/build/import/type/mapped/mapped.d.mts +6 -1
- package/build/import/type/mapped/mapped.mjs +21 -14
- package/build/import/type/not/not.mjs +1 -1
- package/build/import/type/object/object.d.mts +1 -1
- package/build/import/type/object/object.mjs +0 -1
- package/build/import/type/omit/index.d.mts +1 -0
- package/build/import/type/omit/index.mjs +1 -0
- package/build/import/type/omit/omit-from-mapped-key.mjs +4 -5
- package/build/import/type/omit/omit-from-mapped-result.d.mts +11 -0
- package/build/import/type/omit/omit-from-mapped-result.mjs +17 -0
- package/build/import/type/omit/omit.d.mts +6 -3
- package/build/import/type/omit/omit.mjs +11 -9
- package/build/import/type/optional/optional-from-mapped-result.d.mts +5 -5
- package/build/import/type/optional/optional-from-mapped-result.mjs +7 -7
- package/build/import/type/partial/partial-from-mapped-result.d.mts +5 -5
- package/build/import/type/partial/partial-from-mapped-result.mjs +4 -4
- package/build/import/type/partial/partial.d.mts +2 -3
- package/build/import/type/partial/partial.mjs +8 -21
- package/build/import/type/pick/index.d.mts +1 -0
- package/build/import/type/pick/index.mjs +1 -0
- package/build/import/type/pick/pick-from-mapped-key.mjs +4 -5
- package/build/import/type/pick/pick-from-mapped-result.d.mts +11 -0
- package/build/import/type/pick/pick-from-mapped-result.mjs +17 -0
- package/build/import/type/pick/pick.d.mts +5 -2
- package/build/import/type/pick/pick.mjs +11 -10
- package/build/import/type/promise/promise.mjs +1 -1
- package/build/import/type/readonly/readonly-from-mapped-result.d.mts +5 -5
- package/build/import/type/readonly/readonly-from-mapped-result.mjs +4 -4
- package/build/import/type/record/record.d.mts +5 -3
- package/build/import/type/record/record.mjs +13 -5
- package/build/import/type/ref/ref.mjs +1 -1
- package/build/import/type/regexp/regexp.d.mts +11 -4
- package/build/import/type/regexp/regexp.mjs +3 -3
- package/build/import/type/required/required-from-mapped-result.d.mts +5 -5
- package/build/import/type/required/required-from-mapped-result.mjs +7 -7
- package/build/import/type/required/required.d.mts +2 -3
- package/build/import/type/required/required.mjs +4 -14
- package/build/import/type/rest/rest.d.mts +2 -2
- package/build/import/type/rest/rest.mjs +1 -2
- package/build/import/type/schema/anyschema.d.mts +2 -1
- package/build/import/type/sets/index.d.mts +1 -0
- package/build/import/type/sets/index.mjs +1 -0
- package/build/import/type/sets/set.d.mts +24 -0
- package/build/import/type/sets/set.mjs +35 -0
- package/build/import/type/strict/strict.d.mts +1 -1
- package/build/import/type/strict/strict.mjs +1 -1
- package/build/import/type/template-literal/syntax.d.mts +1 -1
- package/build/import/type/template-literal/template-literal.d.mts +1 -1
- package/build/import/type/transform/transform.mjs +1 -1
- package/build/import/type/type/javascript.d.mts +2 -2
- package/build/import/type/type/javascript.mjs +1 -1
- package/build/import/type/type/json.d.mts +6 -2
- package/build/import/type/union/union-evaluated.mjs +3 -14
- package/build/import/value/cast/cast.d.mts +2 -15
- package/build/import/value/cast/cast.mjs +5 -28
- package/build/import/value/check/check.mjs +6 -1
- package/build/import/value/convert/convert.d.mts +0 -5
- package/build/import/value/convert/convert.mjs +0 -12
- package/build/import/value/create/create.d.mts +2 -23
- package/build/import/value/create/create.mjs +30 -53
- package/build/import/value/default/default.mjs +0 -2
- package/build/import/value/delta/delta.d.mts +4 -4
- package/build/import/value/delta/delta.mjs +12 -12
- package/build/import/value/index.d.mts +7 -7
- package/build/import/value/index.mjs +6 -6
- package/build/import/value/mutate/mutate.d.mts +2 -5
- package/build/import/value/mutate/mutate.mjs +5 -10
- package/build/require/compiler/compiler.js +7 -0
- package/build/require/errors/errors.d.ts +16 -15
- package/build/require/errors/errors.js +24 -15
- package/build/require/errors/function.js +2 -0
- package/build/require/index.d.ts +2 -2
- package/build/require/type/awaited/awaited.js +2 -6
- package/build/require/type/clone/value.js +6 -2
- package/build/require/type/composite/composite.d.ts +1 -2
- package/build/require/type/composite/composite.js +5 -6
- package/build/require/type/const/const.js +6 -6
- package/build/require/type/constructor/constructor.d.ts +1 -1
- package/build/require/type/constructor/constructor.js +1 -1
- package/build/require/type/deref/deref.js +0 -1
- package/build/require/type/discard/discard.js +2 -2
- package/build/require/type/enum/enum.js +3 -0
- package/build/require/type/exclude/exclude-from-mapped-result.d.ts +5 -5
- package/build/require/type/exclude/exclude-from-mapped-result.js +7 -7
- package/build/require/type/exclude/exclude.js +0 -1
- package/build/require/type/extends/extends-check.js +137 -125
- package/build/require/type/extends/extends-from-mapped-key.d.ts +1 -1
- package/build/require/type/extends/extends-from-mapped-key.js +4 -5
- package/build/require/type/extends/extends-from-mapped-result.d.ts +5 -5
- package/build/require/type/extends/extends-from-mapped-result.js +7 -7
- package/build/require/type/extends/extends.js +0 -1
- package/build/require/type/extract/extract-from-mapped-result.d.ts +5 -5
- package/build/require/type/extract/extract-from-mapped-result.js +7 -7
- package/build/require/type/extract/extract.d.ts +1 -2
- package/build/require/type/extract/extract.js +4 -3
- package/build/require/type/guard/type.d.ts +3 -0
- package/build/require/type/guard/type.js +12 -1
- package/build/require/type/guard/value.d.ts +2 -0
- package/build/require/type/guard/value.js +6 -1
- package/build/require/type/index.d.ts +1 -1
- package/build/require/type/index.js +1 -1
- package/build/require/type/indexed/indexed-from-mapped-key.d.ts +2 -2
- package/build/require/type/indexed/indexed-from-mapped-key.js +4 -5
- package/build/require/type/indexed/indexed-from-mapped-result.d.ts +1 -1
- package/build/require/type/indexed/indexed-property-keys.d.ts +6 -6
- package/build/require/type/indexed/indexed-property-keys.js +3 -5
- package/build/require/type/indexed/indexed.d.ts +1 -1
- package/build/require/type/indexed/indexed.js +9 -27
- package/build/require/type/intersect/intersect-evaluated.js +3 -13
- package/build/require/type/intrinsic/capitalize.d.ts +2 -2
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.d.ts +1 -1
- package/build/require/type/intrinsic/intrinsic-from-mapped-key.js +4 -5
- package/build/require/type/intrinsic/intrinsic.d.ts +2 -3
- package/build/require/type/intrinsic/intrinsic.js +2 -5
- package/build/require/type/intrinsic/lowercase.d.ts +2 -2
- package/build/require/type/intrinsic/uncapitalize.d.ts +2 -2
- package/build/require/type/intrinsic/uppercase.d.ts +2 -2
- package/build/require/type/iterator/iterator.js +1 -1
- package/build/require/type/keyof/keyof-from-mapped-result.d.ts +3 -3
- package/build/require/type/keyof/keyof-from-mapped-result.js +4 -4
- package/build/require/type/keyof/keyof-property-keys.d.ts +3 -3
- package/build/require/type/keyof/keyof-property-keys.js +9 -15
- package/build/require/type/keyof/keyof.js +2 -8
- package/build/require/type/mapped/mapped.d.ts +6 -1
- package/build/require/type/mapped/mapped.js +21 -14
- package/build/require/type/not/not.js +1 -1
- package/build/require/type/object/object.d.ts +1 -1
- package/build/require/type/object/object.js +0 -1
- package/build/require/type/omit/index.d.ts +1 -0
- package/build/require/type/omit/index.js +1 -0
- package/build/require/type/omit/omit-from-mapped-key.js +4 -5
- package/build/require/type/omit/omit-from-mapped-result.d.ts +11 -0
- package/build/require/type/omit/omit-from-mapped-result.js +22 -0
- package/build/require/type/omit/omit.d.ts +6 -3
- package/build/require/type/omit/omit.js +10 -8
- package/build/require/type/optional/optional-from-mapped-result.d.ts +5 -5
- package/build/require/type/optional/optional-from-mapped-result.js +7 -7
- package/build/require/type/partial/partial-from-mapped-result.d.ts +5 -5
- package/build/require/type/partial/partial-from-mapped-result.js +4 -4
- package/build/require/type/partial/partial.d.ts +2 -3
- package/build/require/type/partial/partial.js +8 -21
- package/build/require/type/pick/index.d.ts +1 -0
- package/build/require/type/pick/index.js +1 -0
- package/build/require/type/pick/pick-from-mapped-key.js +4 -5
- package/build/require/type/pick/pick-from-mapped-result.d.ts +11 -0
- package/build/require/type/pick/pick-from-mapped-result.js +22 -0
- package/build/require/type/pick/pick.d.ts +5 -2
- package/build/require/type/pick/pick.js +10 -9
- package/build/require/type/promise/promise.js +1 -1
- package/build/require/type/readonly/readonly-from-mapped-result.d.ts +5 -5
- package/build/require/type/readonly/readonly-from-mapped-result.js +4 -4
- package/build/require/type/record/record.d.ts +5 -3
- package/build/require/type/record/record.js +12 -4
- package/build/require/type/ref/ref.js +1 -1
- package/build/require/type/regexp/regexp.d.ts +11 -4
- package/build/require/type/regexp/regexp.js +3 -3
- package/build/require/type/required/required-from-mapped-result.d.ts +5 -5
- package/build/require/type/required/required-from-mapped-result.js +7 -7
- package/build/require/type/required/required.d.ts +2 -3
- package/build/require/type/required/required.js +4 -14
- package/build/require/type/rest/rest.d.ts +2 -2
- package/build/require/type/rest/rest.js +1 -3
- package/build/require/type/schema/anyschema.d.ts +2 -1
- package/build/require/type/sets/index.d.ts +1 -0
- package/build/require/type/{operators → sets}/index.js +1 -1
- package/build/require/type/sets/set.d.ts +24 -0
- package/build/require/type/sets/set.js +47 -0
- package/build/require/type/strict/strict.d.ts +1 -1
- package/build/require/type/strict/strict.js +1 -1
- package/build/require/type/template-literal/parse.js +1 -1
- package/build/require/type/template-literal/syntax.d.ts +1 -1
- package/build/require/type/template-literal/template-literal.d.ts +1 -1
- package/build/require/type/transform/transform.js +1 -1
- package/build/require/type/type/javascript.d.ts +2 -2
- package/build/require/type/type/javascript.js +1 -1
- package/build/require/type/type/json.d.ts +6 -2
- package/build/require/type/union/union-evaluated.js +3 -14
- package/build/require/value/cast/cast.d.ts +2 -15
- package/build/require/value/cast/cast.js +7 -29
- package/build/require/value/check/check.js +6 -1
- package/build/require/value/convert/convert.d.ts +0 -5
- package/build/require/value/convert/convert.js +31 -43
- package/build/require/value/create/create.d.ts +2 -23
- package/build/require/value/create/create.js +32 -54
- package/build/require/value/default/default.js +0 -2
- package/build/require/value/delta/delta.d.ts +4 -4
- package/build/require/value/delta/delta.js +14 -14
- package/build/require/value/index.d.ts +7 -7
- package/build/require/value/index.js +8 -19
- package/build/require/value/mutate/mutate.d.ts +2 -5
- package/build/require/value/mutate/mutate.js +7 -13
- package/package.json +1 -1
- package/readme.md +68 -67
- package/build/import/type/operators/index.d.mts +0 -1
- package/build/import/type/operators/index.mjs +0 -1
- package/build/import/type/operators/operators.d.mts +0 -24
- package/build/import/type/operators/operators.mjs +0 -77
- package/build/require/type/operators/index.d.ts +0 -1
- package/build/require/type/operators/operators.d.ts +0 -24
- package/build/require/type/operators/operators.js +0 -89
|
@@ -43,23 +43,23 @@ function IsStructuralRight(right) {
|
|
|
43
43
|
}
|
|
44
44
|
// prettier-ignore
|
|
45
45
|
function StructuralRight(left, right) {
|
|
46
|
-
return (TypeGuard.IsNever(right) ?
|
|
47
|
-
TypeGuard.IsIntersect(right) ?
|
|
48
|
-
TypeGuard.IsUnion(right) ?
|
|
49
|
-
TypeGuard.IsUnknown(right) ?
|
|
50
|
-
TypeGuard.IsAny(right) ?
|
|
46
|
+
return (TypeGuard.IsNever(right) ? FromNeverRight(left, right) :
|
|
47
|
+
TypeGuard.IsIntersect(right) ? FromIntersectRight(left, right) :
|
|
48
|
+
TypeGuard.IsUnion(right) ? FromUnionRight(left, right) :
|
|
49
|
+
TypeGuard.IsUnknown(right) ? FromUnknownRight(left, right) :
|
|
50
|
+
TypeGuard.IsAny(right) ? FromAnyRight(left, right) :
|
|
51
51
|
Throw('StructuralRight'));
|
|
52
52
|
}
|
|
53
53
|
// ------------------------------------------------------------------
|
|
54
54
|
// Any
|
|
55
55
|
// ------------------------------------------------------------------
|
|
56
56
|
// prettier-ignore
|
|
57
|
-
function
|
|
57
|
+
function FromAnyRight(left, right) {
|
|
58
58
|
return ExtendsResult.True;
|
|
59
59
|
}
|
|
60
60
|
// prettier-ignore
|
|
61
|
-
function
|
|
62
|
-
return (TypeGuard.IsIntersect(right) ?
|
|
61
|
+
function FromAny(left, right) {
|
|
62
|
+
return (TypeGuard.IsIntersect(right) ? FromIntersectRight(left, right) :
|
|
63
63
|
(TypeGuard.IsUnion(right) && right.anyOf.some((schema) => TypeGuard.IsAny(schema) || TypeGuard.IsUnknown(schema))) ? ExtendsResult.True :
|
|
64
64
|
TypeGuard.IsUnion(right) ? ExtendsResult.Union :
|
|
65
65
|
TypeGuard.IsUnknown(right) ? ExtendsResult.True :
|
|
@@ -70,14 +70,14 @@ function TAny(left, right) {
|
|
|
70
70
|
// Array
|
|
71
71
|
// ------------------------------------------------------------------
|
|
72
72
|
// prettier-ignore
|
|
73
|
-
function
|
|
73
|
+
function FromArrayRight(left, right) {
|
|
74
74
|
return (TypeGuard.IsUnknown(left) ? ExtendsResult.False :
|
|
75
75
|
TypeGuard.IsAny(left) ? ExtendsResult.Union :
|
|
76
76
|
TypeGuard.IsNever(left) ? ExtendsResult.True :
|
|
77
77
|
ExtendsResult.False);
|
|
78
78
|
}
|
|
79
79
|
// prettier-ignore
|
|
80
|
-
function
|
|
80
|
+
function FromArray(left, right) {
|
|
81
81
|
return (TypeGuard.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True :
|
|
82
82
|
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
83
83
|
!TypeGuard.IsArray(right) ? ExtendsResult.False :
|
|
@@ -87,7 +87,7 @@ function TArray(left, right) {
|
|
|
87
87
|
// AsyncIterator
|
|
88
88
|
// ------------------------------------------------------------------
|
|
89
89
|
// prettier-ignore
|
|
90
|
-
function
|
|
90
|
+
function FromAsyncIterator(left, right) {
|
|
91
91
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
92
92
|
!TypeGuard.IsAsyncIterator(right) ? ExtendsResult.False :
|
|
93
93
|
IntoBooleanResult(Visit(left.items, right.items)));
|
|
@@ -96,10 +96,10 @@ function TAsyncIterator(left, right) {
|
|
|
96
96
|
// BigInt
|
|
97
97
|
// ------------------------------------------------------------------
|
|
98
98
|
// prettier-ignore
|
|
99
|
-
function
|
|
99
|
+
function FromBigInt(left, right) {
|
|
100
100
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
101
|
-
TypeGuard.IsObject(right) ?
|
|
102
|
-
TypeGuard.IsRecord(right) ?
|
|
101
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
102
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
103
103
|
TypeGuard.IsBigInt(right) ? ExtendsResult.True :
|
|
104
104
|
ExtendsResult.False);
|
|
105
105
|
}
|
|
@@ -107,16 +107,16 @@ function TBigInt(left, right) {
|
|
|
107
107
|
// Boolean
|
|
108
108
|
// ------------------------------------------------------------------
|
|
109
109
|
// prettier-ignore
|
|
110
|
-
function
|
|
110
|
+
function FromBooleanRight(left, right) {
|
|
111
111
|
return (TypeGuard.IsLiteralBoolean(left) ? ExtendsResult.True :
|
|
112
112
|
TypeGuard.IsBoolean(left) ? ExtendsResult.True :
|
|
113
113
|
ExtendsResult.False);
|
|
114
114
|
}
|
|
115
115
|
// prettier-ignore
|
|
116
|
-
function
|
|
116
|
+
function FromBoolean(left, right) {
|
|
117
117
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
118
|
-
TypeGuard.IsObject(right) ?
|
|
119
|
-
TypeGuard.IsRecord(right) ?
|
|
118
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
119
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
120
120
|
TypeGuard.IsBoolean(right) ? ExtendsResult.True :
|
|
121
121
|
ExtendsResult.False);
|
|
122
122
|
}
|
|
@@ -124,9 +124,9 @@ function TBoolean(left, right) {
|
|
|
124
124
|
// Constructor
|
|
125
125
|
// ------------------------------------------------------------------
|
|
126
126
|
// prettier-ignore
|
|
127
|
-
function
|
|
127
|
+
function FromConstructor(left, right) {
|
|
128
128
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
129
|
-
TypeGuard.IsObject(right) ?
|
|
129
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
130
130
|
!TypeGuard.IsConstructor(right) ? ExtendsResult.False :
|
|
131
131
|
left.parameters.length > right.parameters.length ? ExtendsResult.False :
|
|
132
132
|
(!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === ExtendsResult.True)) ? ExtendsResult.False :
|
|
@@ -136,10 +136,10 @@ function TConstructor(left, right) {
|
|
|
136
136
|
// Date
|
|
137
137
|
// ------------------------------------------------------------------
|
|
138
138
|
// prettier-ignore
|
|
139
|
-
function
|
|
139
|
+
function FromDate(left, right) {
|
|
140
140
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
141
|
-
TypeGuard.IsObject(right) ?
|
|
142
|
-
TypeGuard.IsRecord(right) ?
|
|
141
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
142
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
143
143
|
TypeGuard.IsDate(right) ? ExtendsResult.True :
|
|
144
144
|
ExtendsResult.False);
|
|
145
145
|
}
|
|
@@ -147,9 +147,9 @@ function TDate(left, right) {
|
|
|
147
147
|
// Function
|
|
148
148
|
// ------------------------------------------------------------------
|
|
149
149
|
// prettier-ignore
|
|
150
|
-
function
|
|
150
|
+
function FromFunction(left, right) {
|
|
151
151
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
152
|
-
TypeGuard.IsObject(right) ?
|
|
152
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
153
153
|
!TypeGuard.IsFunction(right) ? ExtendsResult.False :
|
|
154
154
|
left.parameters.length > right.parameters.length ? ExtendsResult.False :
|
|
155
155
|
(!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === ExtendsResult.True)) ? ExtendsResult.False :
|
|
@@ -159,30 +159,30 @@ function TFunction(left, right) {
|
|
|
159
159
|
// Integer
|
|
160
160
|
// ------------------------------------------------------------------
|
|
161
161
|
// prettier-ignore
|
|
162
|
-
function
|
|
162
|
+
function FromIntegerRight(left, right) {
|
|
163
163
|
return (TypeGuard.IsLiteral(left) && ValueGuard.IsNumber(left.const) ? ExtendsResult.True :
|
|
164
164
|
TypeGuard.IsNumber(left) || TypeGuard.IsInteger(left) ? ExtendsResult.True :
|
|
165
165
|
ExtendsResult.False);
|
|
166
166
|
}
|
|
167
167
|
// prettier-ignore
|
|
168
|
-
function
|
|
168
|
+
function FromInteger(left, right) {
|
|
169
169
|
return (TypeGuard.IsInteger(right) || TypeGuard.IsNumber(right) ? ExtendsResult.True :
|
|
170
170
|
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
171
|
-
TypeGuard.IsObject(right) ?
|
|
172
|
-
TypeGuard.IsRecord(right) ?
|
|
171
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
172
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
173
173
|
ExtendsResult.False);
|
|
174
174
|
}
|
|
175
175
|
// ------------------------------------------------------------------
|
|
176
176
|
// Intersect
|
|
177
177
|
// ------------------------------------------------------------------
|
|
178
178
|
// prettier-ignore
|
|
179
|
-
function
|
|
179
|
+
function FromIntersectRight(left, right) {
|
|
180
180
|
return right.allOf.every((schema) => Visit(left, schema) === ExtendsResult.True)
|
|
181
181
|
? ExtendsResult.True
|
|
182
182
|
: ExtendsResult.False;
|
|
183
183
|
}
|
|
184
184
|
// prettier-ignore
|
|
185
|
-
function
|
|
185
|
+
function FromIntersect(left, right) {
|
|
186
186
|
return left.allOf.some((schema) => Visit(schema, right) === ExtendsResult.True)
|
|
187
187
|
? ExtendsResult.True
|
|
188
188
|
: ExtendsResult.False;
|
|
@@ -191,7 +191,7 @@ function TIntersect(left, right) {
|
|
|
191
191
|
// Iterator
|
|
192
192
|
// ------------------------------------------------------------------
|
|
193
193
|
// prettier-ignore
|
|
194
|
-
function
|
|
194
|
+
function FromIterator(left, right) {
|
|
195
195
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
196
196
|
!TypeGuard.IsIterator(right) ? ExtendsResult.False :
|
|
197
197
|
IntoBooleanResult(Visit(left.items, right.items)));
|
|
@@ -200,26 +200,26 @@ function TIterator(left, right) {
|
|
|
200
200
|
// Literal
|
|
201
201
|
// ------------------------------------------------------------------
|
|
202
202
|
// prettier-ignore
|
|
203
|
-
function
|
|
203
|
+
function FromLiteral(left, right) {
|
|
204
204
|
return (TypeGuard.IsLiteral(right) && right.const === left.const ? ExtendsResult.True :
|
|
205
205
|
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
206
|
-
TypeGuard.IsObject(right) ?
|
|
207
|
-
TypeGuard.IsRecord(right) ?
|
|
208
|
-
TypeGuard.IsString(right) ?
|
|
209
|
-
TypeGuard.IsNumber(right) ?
|
|
210
|
-
TypeGuard.IsInteger(right) ?
|
|
211
|
-
TypeGuard.IsBoolean(right) ?
|
|
206
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
207
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
208
|
+
TypeGuard.IsString(right) ? FromStringRight(left, right) :
|
|
209
|
+
TypeGuard.IsNumber(right) ? FromNumberRight(left, right) :
|
|
210
|
+
TypeGuard.IsInteger(right) ? FromIntegerRight(left, right) :
|
|
211
|
+
TypeGuard.IsBoolean(right) ? FromBooleanRight(left, right) :
|
|
212
212
|
ExtendsResult.False);
|
|
213
213
|
}
|
|
214
214
|
// ------------------------------------------------------------------
|
|
215
215
|
// Never
|
|
216
216
|
// ------------------------------------------------------------------
|
|
217
217
|
// prettier-ignore
|
|
218
|
-
function
|
|
218
|
+
function FromNeverRight(left, right) {
|
|
219
219
|
return ExtendsResult.False;
|
|
220
220
|
}
|
|
221
221
|
// prettier-ignore
|
|
222
|
-
function
|
|
222
|
+
function FromNever(left, right) {
|
|
223
223
|
return ExtendsResult.True;
|
|
224
224
|
}
|
|
225
225
|
// ------------------------------------------------------------------
|
|
@@ -237,7 +237,7 @@ function UnwrapTNot(schema) {
|
|
|
237
237
|
return depth % 2 === 0 ? current : Unknown();
|
|
238
238
|
}
|
|
239
239
|
// prettier-ignore
|
|
240
|
-
function
|
|
240
|
+
function FromNot(left, right) {
|
|
241
241
|
// TypeScript has no concept of negated types, and attempts to correctly check the negated
|
|
242
242
|
// type at runtime would put TypeBox at odds with TypeScripts ability to statically infer
|
|
243
243
|
// the type. Instead we unwrap to either unknown or T and continue evaluating.
|
|
@@ -250,10 +250,10 @@ function TNot(left, right) {
|
|
|
250
250
|
// Null
|
|
251
251
|
// ------------------------------------------------------------------
|
|
252
252
|
// prettier-ignore
|
|
253
|
-
function
|
|
253
|
+
function FromNull(left, right) {
|
|
254
254
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
255
|
-
TypeGuard.IsObject(right) ?
|
|
256
|
-
TypeGuard.IsRecord(right) ?
|
|
255
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
256
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
257
257
|
TypeGuard.IsNull(right) ? ExtendsResult.True :
|
|
258
258
|
ExtendsResult.False);
|
|
259
259
|
}
|
|
@@ -261,16 +261,16 @@ function TNull(left, right) {
|
|
|
261
261
|
// Number
|
|
262
262
|
// ------------------------------------------------------------------
|
|
263
263
|
// prettier-ignore
|
|
264
|
-
function
|
|
264
|
+
function FromNumberRight(left, right) {
|
|
265
265
|
return (TypeGuard.IsLiteralNumber(left) ? ExtendsResult.True :
|
|
266
266
|
TypeGuard.IsNumber(left) || TypeGuard.IsInteger(left) ? ExtendsResult.True :
|
|
267
267
|
ExtendsResult.False);
|
|
268
268
|
}
|
|
269
269
|
// prettier-ignore
|
|
270
|
-
function
|
|
270
|
+
function FromNumber(left, right) {
|
|
271
271
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
272
|
-
TypeGuard.IsObject(right) ?
|
|
273
|
-
TypeGuard.IsRecord(right) ?
|
|
272
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
273
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
274
274
|
TypeGuard.IsInteger(right) || TypeGuard.IsNumber(right) ? ExtendsResult.True :
|
|
275
275
|
ExtendsResult.False);
|
|
276
276
|
}
|
|
@@ -340,7 +340,7 @@ function Property(left, right) {
|
|
|
340
340
|
ExtendsResult.True);
|
|
341
341
|
}
|
|
342
342
|
// prettier-ignore
|
|
343
|
-
function
|
|
343
|
+
function FromObjectRight(left, right) {
|
|
344
344
|
return (TypeGuard.IsUnknown(left) ? ExtendsResult.False :
|
|
345
345
|
TypeGuard.IsAny(left) ? ExtendsResult.Union : (TypeGuard.IsNever(left) ||
|
|
346
346
|
(TypeGuard.IsLiteralString(left) && IsObjectStringLike(right)) ||
|
|
@@ -368,9 +368,9 @@ function TObjectRight(left, right) {
|
|
|
368
368
|
ExtendsResult.False);
|
|
369
369
|
}
|
|
370
370
|
// prettier-ignore
|
|
371
|
-
function
|
|
371
|
+
function FromObject(left, right) {
|
|
372
372
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
373
|
-
TypeGuard.IsRecord(right) ?
|
|
373
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
374
374
|
!TypeGuard.IsObject(right) ? ExtendsResult.False :
|
|
375
375
|
(() => {
|
|
376
376
|
for (const key of Object.getOwnPropertyNames(right.properties)) {
|
|
@@ -391,7 +391,7 @@ function TObject(left, right) {
|
|
|
391
391
|
// Promise
|
|
392
392
|
// ------------------------------------------------------------------
|
|
393
393
|
// prettier-ignore
|
|
394
|
-
function
|
|
394
|
+
function FromPromise(left, right) {
|
|
395
395
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
396
396
|
TypeGuard.IsObject(right) && IsObjectPromiseLike(right) ? ExtendsResult.True :
|
|
397
397
|
!TypeGuard.IsPromise(right) ? ExtendsResult.False :
|
|
@@ -413,7 +413,7 @@ function RecordValue(schema) {
|
|
|
413
413
|
Throw('Unable to get record value schema'));
|
|
414
414
|
}
|
|
415
415
|
// prettier-ignore
|
|
416
|
-
function
|
|
416
|
+
function FromRecordRight(left, right) {
|
|
417
417
|
const [Key, Value] = [RecordKey(right), RecordValue(right)];
|
|
418
418
|
return ((TypeGuard.IsLiteralString(left) && TypeGuard.IsNumber(Key) && IntoBooleanResult(Visit(left, Value)) === ExtendsResult.True) ? ExtendsResult.True :
|
|
419
419
|
TypeGuard.IsUint8Array(left) && TypeGuard.IsNumber(Key) ? Visit(left, Value) :
|
|
@@ -430,26 +430,37 @@ function TRecordRight(left, right) {
|
|
|
430
430
|
ExtendsResult.False);
|
|
431
431
|
}
|
|
432
432
|
// prettier-ignore
|
|
433
|
-
function
|
|
433
|
+
function FromRecord(left, right) {
|
|
434
434
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
435
|
-
TypeGuard.IsObject(right) ?
|
|
435
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
436
436
|
!TypeGuard.IsRecord(right) ? ExtendsResult.False :
|
|
437
437
|
Visit(RecordValue(left), RecordValue(right)));
|
|
438
438
|
}
|
|
439
439
|
// ------------------------------------------------------------------
|
|
440
|
+
// RegExp
|
|
441
|
+
// ------------------------------------------------------------------
|
|
442
|
+
// prettier-ignore
|
|
443
|
+
function FromRegExp(left, right) {
|
|
444
|
+
// Note: RegExp types evaluate as strings, not RegExp objects.
|
|
445
|
+
// Here we remap either into string and continue evaluating.
|
|
446
|
+
const L = TypeGuard.IsRegExp(left) ? String() : left;
|
|
447
|
+
const R = TypeGuard.IsRegExp(right) ? String() : right;
|
|
448
|
+
return Visit(L, R);
|
|
449
|
+
}
|
|
450
|
+
// ------------------------------------------------------------------
|
|
440
451
|
// String
|
|
441
452
|
// ------------------------------------------------------------------
|
|
442
453
|
// prettier-ignore
|
|
443
|
-
function
|
|
454
|
+
function FromStringRight(left, right) {
|
|
444
455
|
return (TypeGuard.IsLiteral(left) && ValueGuard.IsString(left.const) ? ExtendsResult.True :
|
|
445
456
|
TypeGuard.IsString(left) ? ExtendsResult.True :
|
|
446
457
|
ExtendsResult.False);
|
|
447
458
|
}
|
|
448
459
|
// prettier-ignore
|
|
449
|
-
function
|
|
460
|
+
function FromString(left, right) {
|
|
450
461
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
451
|
-
TypeGuard.IsObject(right) ?
|
|
452
|
-
TypeGuard.IsRecord(right) ?
|
|
462
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
463
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
453
464
|
TypeGuard.IsString(right) ? ExtendsResult.True :
|
|
454
465
|
ExtendsResult.False);
|
|
455
466
|
}
|
|
@@ -457,10 +468,10 @@ function TString(left, right) {
|
|
|
457
468
|
// Symbol
|
|
458
469
|
// ------------------------------------------------------------------
|
|
459
470
|
// prettier-ignore
|
|
460
|
-
function
|
|
471
|
+
function FromSymbol(left, right) {
|
|
461
472
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
462
|
-
TypeGuard.IsObject(right) ?
|
|
463
|
-
TypeGuard.IsRecord(right) ?
|
|
473
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
474
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
464
475
|
TypeGuard.IsSymbol(right) ? ExtendsResult.True :
|
|
465
476
|
ExtendsResult.False);
|
|
466
477
|
}
|
|
@@ -468,7 +479,7 @@ function TSymbol(left, right) {
|
|
|
468
479
|
// TemplateLiteral
|
|
469
480
|
// ------------------------------------------------------------------
|
|
470
481
|
// prettier-ignore
|
|
471
|
-
function
|
|
482
|
+
function FromTemplateLiteral(left, right) {
|
|
472
483
|
// TemplateLiteral types are resolved to either unions for finite expressions or string
|
|
473
484
|
// for infinite expressions. Here we call to TemplateLiteralResolver to resolve for
|
|
474
485
|
// either type and continue evaluating.
|
|
@@ -486,14 +497,14 @@ function IsArrayOfTuple(left, right) {
|
|
|
486
497
|
left.items.every((schema) => Visit(schema, right.items) === ExtendsResult.True));
|
|
487
498
|
}
|
|
488
499
|
// prettier-ignore
|
|
489
|
-
function
|
|
500
|
+
function FromTupleRight(left, right) {
|
|
490
501
|
return (TypeGuard.IsNever(left) ? ExtendsResult.True :
|
|
491
502
|
TypeGuard.IsUnknown(left) ? ExtendsResult.False :
|
|
492
503
|
TypeGuard.IsAny(left) ? ExtendsResult.Union :
|
|
493
504
|
ExtendsResult.False);
|
|
494
505
|
}
|
|
495
506
|
// prettier-ignore
|
|
496
|
-
function
|
|
507
|
+
function FromTuple(left, right) {
|
|
497
508
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
498
509
|
TypeGuard.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True :
|
|
499
510
|
TypeGuard.IsArray(right) && IsArrayOfTuple(left, right) ? ExtendsResult.True :
|
|
@@ -507,10 +518,10 @@ function TTuple(left, right) {
|
|
|
507
518
|
// Uint8Array
|
|
508
519
|
// ------------------------------------------------------------------
|
|
509
520
|
// prettier-ignore
|
|
510
|
-
function
|
|
521
|
+
function FromUint8Array(left, right) {
|
|
511
522
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
512
|
-
TypeGuard.IsObject(right) ?
|
|
513
|
-
TypeGuard.IsRecord(right) ?
|
|
523
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
524
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
514
525
|
TypeGuard.IsUint8Array(right) ? ExtendsResult.True :
|
|
515
526
|
ExtendsResult.False);
|
|
516
527
|
}
|
|
@@ -518,11 +529,11 @@ function TUint8Array(left, right) {
|
|
|
518
529
|
// Undefined
|
|
519
530
|
// ------------------------------------------------------------------
|
|
520
531
|
// prettier-ignore
|
|
521
|
-
function
|
|
532
|
+
function FromUndefined(left, right) {
|
|
522
533
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
523
|
-
TypeGuard.IsObject(right) ?
|
|
524
|
-
TypeGuard.IsRecord(right) ?
|
|
525
|
-
TypeGuard.IsVoid(right) ?
|
|
534
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
535
|
+
TypeGuard.IsRecord(right) ? FromRecordRight(left, right) :
|
|
536
|
+
TypeGuard.IsVoid(right) ? FromVoidRight(left, right) :
|
|
526
537
|
TypeGuard.IsUndefined(right) ? ExtendsResult.True :
|
|
527
538
|
ExtendsResult.False);
|
|
528
539
|
}
|
|
@@ -530,13 +541,13 @@ function TUndefined(left, right) {
|
|
|
530
541
|
// Union
|
|
531
542
|
// ------------------------------------------------------------------
|
|
532
543
|
// prettier-ignore
|
|
533
|
-
function
|
|
544
|
+
function FromUnionRight(left, right) {
|
|
534
545
|
return right.anyOf.some((schema) => Visit(left, schema) === ExtendsResult.True)
|
|
535
546
|
? ExtendsResult.True
|
|
536
547
|
: ExtendsResult.False;
|
|
537
548
|
}
|
|
538
549
|
// prettier-ignore
|
|
539
|
-
function
|
|
550
|
+
function FromUnion(left, right) {
|
|
540
551
|
return left.anyOf.every((schema) => Visit(schema, right) === ExtendsResult.True)
|
|
541
552
|
? ExtendsResult.True
|
|
542
553
|
: ExtendsResult.False;
|
|
@@ -545,22 +556,22 @@ function TUnion(left, right) {
|
|
|
545
556
|
// Unknown
|
|
546
557
|
// ------------------------------------------------------------------
|
|
547
558
|
// prettier-ignore
|
|
548
|
-
function
|
|
559
|
+
function FromUnknownRight(left, right) {
|
|
549
560
|
return ExtendsResult.True;
|
|
550
561
|
}
|
|
551
562
|
// prettier-ignore
|
|
552
|
-
function
|
|
553
|
-
return (TypeGuard.IsNever(right) ?
|
|
554
|
-
TypeGuard.IsIntersect(right) ?
|
|
555
|
-
TypeGuard.IsUnion(right) ?
|
|
556
|
-
TypeGuard.IsAny(right) ?
|
|
557
|
-
TypeGuard.IsString(right) ?
|
|
558
|
-
TypeGuard.IsNumber(right) ?
|
|
559
|
-
TypeGuard.IsInteger(right) ?
|
|
560
|
-
TypeGuard.IsBoolean(right) ?
|
|
561
|
-
TypeGuard.IsArray(right) ?
|
|
562
|
-
TypeGuard.IsTuple(right) ?
|
|
563
|
-
TypeGuard.IsObject(right) ?
|
|
563
|
+
function FromUnknown(left, right) {
|
|
564
|
+
return (TypeGuard.IsNever(right) ? FromNeverRight(left, right) :
|
|
565
|
+
TypeGuard.IsIntersect(right) ? FromIntersectRight(left, right) :
|
|
566
|
+
TypeGuard.IsUnion(right) ? FromUnionRight(left, right) :
|
|
567
|
+
TypeGuard.IsAny(right) ? FromAnyRight(left, right) :
|
|
568
|
+
TypeGuard.IsString(right) ? FromStringRight(left, right) :
|
|
569
|
+
TypeGuard.IsNumber(right) ? FromNumberRight(left, right) :
|
|
570
|
+
TypeGuard.IsInteger(right) ? FromIntegerRight(left, right) :
|
|
571
|
+
TypeGuard.IsBoolean(right) ? FromBooleanRight(left, right) :
|
|
572
|
+
TypeGuard.IsArray(right) ? FromArrayRight(left, right) :
|
|
573
|
+
TypeGuard.IsTuple(right) ? FromTupleRight(left, right) :
|
|
574
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
564
575
|
TypeGuard.IsUnknown(right) ? ExtendsResult.True :
|
|
565
576
|
ExtendsResult.False);
|
|
566
577
|
}
|
|
@@ -568,18 +579,18 @@ function TUnknown(left, right) {
|
|
|
568
579
|
// Void
|
|
569
580
|
// ------------------------------------------------------------------
|
|
570
581
|
// prettier-ignore
|
|
571
|
-
function
|
|
582
|
+
function FromVoidRight(left, right) {
|
|
572
583
|
return (TypeGuard.IsUndefined(left) ? ExtendsResult.True :
|
|
573
584
|
TypeGuard.IsUndefined(left) ? ExtendsResult.True :
|
|
574
585
|
ExtendsResult.False);
|
|
575
586
|
}
|
|
576
587
|
// prettier-ignore
|
|
577
|
-
function
|
|
578
|
-
return (TypeGuard.IsIntersect(right) ?
|
|
579
|
-
TypeGuard.IsUnion(right) ?
|
|
580
|
-
TypeGuard.IsUnknown(right) ?
|
|
581
|
-
TypeGuard.IsAny(right) ?
|
|
582
|
-
TypeGuard.IsObject(right) ?
|
|
588
|
+
function FromVoid(left, right) {
|
|
589
|
+
return (TypeGuard.IsIntersect(right) ? FromIntersectRight(left, right) :
|
|
590
|
+
TypeGuard.IsUnion(right) ? FromUnionRight(left, right) :
|
|
591
|
+
TypeGuard.IsUnknown(right) ? FromUnknownRight(left, right) :
|
|
592
|
+
TypeGuard.IsAny(right) ? FromAnyRight(left, right) :
|
|
593
|
+
TypeGuard.IsObject(right) ? FromObjectRight(left, right) :
|
|
583
594
|
TypeGuard.IsVoid(right) ? ExtendsResult.True :
|
|
584
595
|
ExtendsResult.False);
|
|
585
596
|
}
|
|
@@ -587,36 +598,37 @@ function TVoid(left, right) {
|
|
|
587
598
|
function Visit(left, right) {
|
|
588
599
|
return (
|
|
589
600
|
// resolvable
|
|
590
|
-
(TypeGuard.IsTemplateLiteral(left) || TypeGuard.IsTemplateLiteral(right)) ?
|
|
591
|
-
(TypeGuard.
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
TypeGuard.
|
|
595
|
-
TypeGuard.
|
|
596
|
-
TypeGuard.
|
|
597
|
-
TypeGuard.
|
|
598
|
-
TypeGuard.
|
|
599
|
-
TypeGuard.
|
|
600
|
-
TypeGuard.
|
|
601
|
-
TypeGuard.
|
|
602
|
-
TypeGuard.
|
|
603
|
-
TypeGuard.
|
|
604
|
-
TypeGuard.
|
|
605
|
-
TypeGuard.
|
|
606
|
-
TypeGuard.
|
|
607
|
-
TypeGuard.
|
|
608
|
-
TypeGuard.
|
|
609
|
-
TypeGuard.
|
|
610
|
-
TypeGuard.
|
|
611
|
-
TypeGuard.
|
|
612
|
-
TypeGuard.
|
|
613
|
-
TypeGuard.
|
|
614
|
-
TypeGuard.
|
|
615
|
-
TypeGuard.
|
|
616
|
-
TypeGuard.
|
|
617
|
-
TypeGuard.
|
|
618
|
-
TypeGuard.
|
|
619
|
-
|
|
601
|
+
(TypeGuard.IsTemplateLiteral(left) || TypeGuard.IsTemplateLiteral(right)) ? FromTemplateLiteral(left, right) :
|
|
602
|
+
(TypeGuard.IsRegExp(left) || TypeGuard.IsRegExp(right)) ? FromRegExp(left, right) :
|
|
603
|
+
(TypeGuard.IsNot(left) || TypeGuard.IsNot(right)) ? FromNot(left, right) :
|
|
604
|
+
// standard
|
|
605
|
+
TypeGuard.IsAny(left) ? FromAny(left, right) :
|
|
606
|
+
TypeGuard.IsArray(left) ? FromArray(left, right) :
|
|
607
|
+
TypeGuard.IsBigInt(left) ? FromBigInt(left, right) :
|
|
608
|
+
TypeGuard.IsBoolean(left) ? FromBoolean(left, right) :
|
|
609
|
+
TypeGuard.IsAsyncIterator(left) ? FromAsyncIterator(left, right) :
|
|
610
|
+
TypeGuard.IsConstructor(left) ? FromConstructor(left, right) :
|
|
611
|
+
TypeGuard.IsDate(left) ? FromDate(left, right) :
|
|
612
|
+
TypeGuard.IsFunction(left) ? FromFunction(left, right) :
|
|
613
|
+
TypeGuard.IsInteger(left) ? FromInteger(left, right) :
|
|
614
|
+
TypeGuard.IsIntersect(left) ? FromIntersect(left, right) :
|
|
615
|
+
TypeGuard.IsIterator(left) ? FromIterator(left, right) :
|
|
616
|
+
TypeGuard.IsLiteral(left) ? FromLiteral(left, right) :
|
|
617
|
+
TypeGuard.IsNever(left) ? FromNever(left, right) :
|
|
618
|
+
TypeGuard.IsNull(left) ? FromNull(left, right) :
|
|
619
|
+
TypeGuard.IsNumber(left) ? FromNumber(left, right) :
|
|
620
|
+
TypeGuard.IsObject(left) ? FromObject(left, right) :
|
|
621
|
+
TypeGuard.IsRecord(left) ? FromRecord(left, right) :
|
|
622
|
+
TypeGuard.IsString(left) ? FromString(left, right) :
|
|
623
|
+
TypeGuard.IsSymbol(left) ? FromSymbol(left, right) :
|
|
624
|
+
TypeGuard.IsTuple(left) ? FromTuple(left, right) :
|
|
625
|
+
TypeGuard.IsPromise(left) ? FromPromise(left, right) :
|
|
626
|
+
TypeGuard.IsUint8Array(left) ? FromUint8Array(left, right) :
|
|
627
|
+
TypeGuard.IsUndefined(left) ? FromUndefined(left, right) :
|
|
628
|
+
TypeGuard.IsUnion(left) ? FromUnion(left, right) :
|
|
629
|
+
TypeGuard.IsUnknown(left) ? FromUnknown(left, right) :
|
|
630
|
+
TypeGuard.IsVoid(left) ? FromVoid(left, right) :
|
|
631
|
+
Throw(`Unknown left type operand '${left[Kind]}'`));
|
|
620
632
|
}
|
|
621
633
|
export function ExtendsCheck(left, right) {
|
|
622
634
|
return Visit(left, right);
|
|
@@ -2,7 +2,7 @@ import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
|
2
2
|
import type { TProperties } from '../object/index.mjs';
|
|
3
3
|
import type { Assert } from '../helpers/index.mjs';
|
|
4
4
|
import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
|
|
5
|
-
import { TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
5
|
+
import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
|
|
6
6
|
import { type TExtends } from './extends.mjs';
|
|
7
7
|
type TFromPropertyKey<K extends PropertyKey, U extends TSchema, L extends TSchema, R extends TSchema> = {
|
|
8
8
|
[_ in K]: TExtends<TLiteral<Assert<K, TLiteralValue>>, U, L, R>;
|
|
@@ -8,11 +8,10 @@ function FromPropertyKey(K, U, L, R, options) {
|
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
// prettier-ignore
|
|
11
|
-
function FromPropertyKeys(K, U, L, R, options
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
: Acc);
|
|
11
|
+
function FromPropertyKeys(K, U, L, R, options) {
|
|
12
|
+
return K.reduce((Acc, LK) => {
|
|
13
|
+
return { ...Acc, ...FromPropertyKey(LK, U, L, R, options) };
|
|
14
|
+
}, {});
|
|
16
15
|
}
|
|
17
16
|
// prettier-ignore
|
|
18
17
|
function FromMappedKey(K, U, L, R, options) {
|
|
@@ -2,10 +2,10 @@ import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
|
2
2
|
import type { TProperties } from '../object/index.mjs';
|
|
3
3
|
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
4
|
import { type TExtends } from './extends.mjs';
|
|
5
|
-
type TFromProperties<
|
|
6
|
-
[K2 in keyof
|
|
5
|
+
type TFromProperties<P extends TProperties, Right extends TSchema, False extends TSchema, True extends TSchema> = ({
|
|
6
|
+
[K2 in keyof P]: TExtends<P[K2], Right, False, True>;
|
|
7
7
|
});
|
|
8
|
-
type TFromMappedResult<
|
|
9
|
-
export type TExtendsFromMappedResult<
|
|
10
|
-
export declare function ExtendsFromMappedResult<
|
|
8
|
+
type TFromMappedResult<Left extends TMappedResult, Right extends TSchema, True extends TSchema, False extends TSchema> = (TFromProperties<Left['properties'], Right, True, False>);
|
|
9
|
+
export type TExtendsFromMappedResult<Left extends TMappedResult, Right extends TSchema, True extends TSchema, False extends TSchema, P extends TProperties = TFromMappedResult<Left, Right, True, False>> = (TMappedResult<P>);
|
|
10
|
+
export declare function ExtendsFromMappedResult<Left extends TMappedResult, Right extends TSchema, True extends TSchema, False extends TSchema, P extends TProperties = TFromMappedResult<Left, Right, True, False>>(Left: Left, Right: Right, True: True, False: False, options: SchemaOptions): TMappedResult<P>;
|
|
11
11
|
export {};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { MappedResult } from '../mapped/index.mjs';
|
|
2
2
|
import { Extends } from './extends.mjs';
|
|
3
3
|
// prettier-ignore
|
|
4
|
-
function FromProperties(
|
|
5
|
-
return globalThis.Object.getOwnPropertyNames(
|
|
6
|
-
return { ...Acc, [K2]: Extends(
|
|
4
|
+
function FromProperties(P, Right, True, False, options) {
|
|
5
|
+
return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
|
|
6
|
+
return { ...Acc, [K2]: Extends(P[K2], Right, True, False, options) };
|
|
7
7
|
}, {});
|
|
8
8
|
}
|
|
9
9
|
// prettier-ignore
|
|
10
|
-
function FromMappedResult(
|
|
11
|
-
return FromProperties(
|
|
10
|
+
function FromMappedResult(Left, Right, True, False, options) {
|
|
11
|
+
return FromProperties(Left.properties, Right, True, False, options);
|
|
12
12
|
}
|
|
13
13
|
// prettier-ignore
|
|
14
|
-
export function ExtendsFromMappedResult(
|
|
15
|
-
const P = FromMappedResult(
|
|
14
|
+
export function ExtendsFromMappedResult(Left, Right, True, False, options) {
|
|
15
|
+
const P = FromMappedResult(Left, Right, True, False, options);
|
|
16
16
|
return MappedResult(P);
|
|
17
17
|
}
|
|
@@ -6,7 +6,6 @@ import { ExtendsFromMappedResult } from './extends-from-mapped-result.mjs';
|
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
7
|
// TypeGuard
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
|
-
// prettier-ignore
|
|
10
9
|
import { IsMappedKey, IsMappedResult } from '../guard/type.mjs';
|
|
11
10
|
// prettier-ignore
|
|
12
11
|
function ExtendsResolve(left, right, trueType, falseType) {
|