@sinclair/typebox 0.32.0-dev-18 → 0.32.0-dev-19
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 +14 -8
- package/build/import/errors/errors.mjs +15 -11
- package/build/import/type/awaited/awaited.mjs +4 -4
- package/build/import/type/deref/deref.mjs +12 -12
- package/build/import/type/exclude/exclude.mjs +8 -5
- package/build/import/type/extends/extends-check.mjs +167 -167
- package/build/import/type/extends/extends.mjs +3 -3
- package/build/import/type/extract/extract.mjs +5 -5
- package/build/import/type/guard/type.d.mts +50 -50
- package/build/import/type/guard/type.mjs +136 -136
- package/build/import/type/indexed/indexed-property-keys.mjs +7 -7
- package/build/import/type/indexed/indexed.mjs +9 -9
- package/build/import/type/intersect/intersect-create.mjs +4 -4
- package/build/import/type/intersect/intersect-evaluated.mjs +1 -1
- package/build/import/type/intersect/intersect.mjs +2 -2
- package/build/import/type/intrinsic/intrinsic.mjs +5 -5
- package/build/import/type/keyof/keyof-property-keys.mjs +7 -7
- package/build/import/type/keyof/keyof.mjs +2 -2
- package/build/import/type/mapped/mapped.mjs +16 -16
- package/build/import/type/modifiers/modifiers.mjs +3 -3
- package/build/import/type/object/object.mjs +3 -3
- package/build/import/type/omit/omit.mjs +6 -6
- package/build/import/type/partial/partial.mjs +5 -5
- package/build/import/type/pick/pick.mjs +6 -6
- package/build/import/type/record/record.mjs +7 -7
- package/build/import/type/required/required.mjs +5 -5
- package/build/import/type/rest/rest.mjs +6 -2
- package/build/import/type/template-literal/pattern.mjs +9 -9
- package/build/import/type/transform/transform.mjs +1 -1
- package/build/import/type/union/union-evaluated.mjs +2 -2
- package/build/import/value/check/check.mjs +18 -11
- package/build/import/value/clean/clean.mjs +9 -7
- package/build/import/value/clone/clone.mjs +7 -4
- package/build/import/value/convert/convert.mjs +6 -2
- package/build/import/value/default/default.mjs +12 -4
- package/build/import/value/transform/decode.mjs +12 -6
- package/build/import/value/transform/encode.mjs +12 -6
- package/build/import/value/transform/has.mjs +24 -18
- package/build/require/compiler/compiler.js +77 -71
- package/build/require/errors/errors.js +58 -54
- package/build/require/type/awaited/awaited.js +3 -3
- package/build/require/type/deref/deref.js +11 -11
- package/build/require/type/exclude/exclude.js +7 -4
- package/build/require/type/extends/extends-check.js +167 -167
- package/build/require/type/extends/extends.js +2 -2
- package/build/require/type/extract/extract.js +4 -4
- package/build/require/type/guard/type.d.ts +50 -50
- package/build/require/type/guard/type.js +184 -184
- package/build/require/type/indexed/indexed-property-keys.js +6 -6
- package/build/require/type/indexed/indexed.js +9 -9
- package/build/require/type/intersect/intersect-create.js +3 -3
- package/build/require/type/intersect/intersect-evaluated.js +2 -2
- package/build/require/type/intersect/intersect.js +1 -1
- package/build/require/type/intrinsic/intrinsic.js +4 -4
- package/build/require/type/keyof/keyof-property-keys.js +6 -6
- package/build/require/type/keyof/keyof.js +1 -1
- package/build/require/type/mapped/mapped.js +15 -15
- package/build/require/type/modifiers/modifiers.js +2 -2
- package/build/require/type/object/object.js +2 -2
- package/build/require/type/omit/omit.js +5 -5
- package/build/require/type/partial/partial.js +4 -4
- package/build/require/type/pick/pick.js +5 -5
- package/build/require/type/record/record.js +6 -6
- package/build/require/type/required/required.js +4 -4
- package/build/require/type/rest/rest.js +5 -1
- package/build/require/type/template-literal/pattern.js +8 -8
- package/build/require/type/transform/transform.js +1 -1
- package/build/require/type/union/union-evaluated.js +1 -1
- package/build/require/value/check/check.js +63 -56
- package/build/require/value/clean/clean.js +31 -29
- package/build/require/value/clone/clone.js +7 -4
- package/build/require/value/convert/convert.js +42 -38
- package/build/require/value/default/default.js +24 -16
- package/build/require/value/transform/decode.js +27 -21
- package/build/require/value/transform/encode.js +28 -22
- package/build/require/value/transform/has.js +29 -23
- package/package.json +1 -1
- package/readme.md +5 -5
|
@@ -34,19 +34,19 @@ function Throw(message) {
|
|
|
34
34
|
// ------------------------------------------------------------------
|
|
35
35
|
// prettier-ignore
|
|
36
36
|
function IsStructuralRight(right) {
|
|
37
|
-
return (TypeGuard.
|
|
38
|
-
TypeGuard.
|
|
39
|
-
TypeGuard.
|
|
40
|
-
TypeGuard.
|
|
41
|
-
TypeGuard.
|
|
37
|
+
return (TypeGuard.IsNever(right) ||
|
|
38
|
+
TypeGuard.IsIntersect(right) ||
|
|
39
|
+
TypeGuard.IsUnion(right) ||
|
|
40
|
+
TypeGuard.IsUnknown(right) ||
|
|
41
|
+
TypeGuard.IsAny(right));
|
|
42
42
|
}
|
|
43
43
|
// prettier-ignore
|
|
44
44
|
function StructuralRight(left, right) {
|
|
45
|
-
return (TypeGuard.
|
|
46
|
-
TypeGuard.
|
|
47
|
-
TypeGuard.
|
|
48
|
-
TypeGuard.
|
|
49
|
-
TypeGuard.
|
|
45
|
+
return (TypeGuard.IsNever(right) ? TNeverRight(left, right) :
|
|
46
|
+
TypeGuard.IsIntersect(right) ? TIntersectRight(left, right) :
|
|
47
|
+
TypeGuard.IsUnion(right) ? TUnionRight(left, right) :
|
|
48
|
+
TypeGuard.IsUnknown(right) ? TUnknownRight(left, right) :
|
|
49
|
+
TypeGuard.IsAny(right) ? TAnyRight(left, right) :
|
|
50
50
|
Throw('StructuralRight'));
|
|
51
51
|
}
|
|
52
52
|
// ------------------------------------------------------------------
|
|
@@ -58,11 +58,11 @@ function TAnyRight(left, right) {
|
|
|
58
58
|
}
|
|
59
59
|
// prettier-ignore
|
|
60
60
|
function TAny(left, right) {
|
|
61
|
-
return (TypeGuard.
|
|
62
|
-
(TypeGuard.
|
|
63
|
-
TypeGuard.
|
|
64
|
-
TypeGuard.
|
|
65
|
-
TypeGuard.
|
|
61
|
+
return (TypeGuard.IsIntersect(right) ? TIntersectRight(left, right) :
|
|
62
|
+
(TypeGuard.IsUnion(right) && right.anyOf.some((schema) => TypeGuard.IsAny(schema) || TypeGuard.IsUnknown(schema))) ? ExtendsResult.True :
|
|
63
|
+
TypeGuard.IsUnion(right) ? ExtendsResult.Union :
|
|
64
|
+
TypeGuard.IsUnknown(right) ? ExtendsResult.True :
|
|
65
|
+
TypeGuard.IsAny(right) ? ExtendsResult.True :
|
|
66
66
|
ExtendsResult.Union);
|
|
67
67
|
}
|
|
68
68
|
// ------------------------------------------------------------------
|
|
@@ -70,16 +70,16 @@ function TAny(left, right) {
|
|
|
70
70
|
// ------------------------------------------------------------------
|
|
71
71
|
// prettier-ignore
|
|
72
72
|
function TArrayRight(left, right) {
|
|
73
|
-
return (TypeGuard.
|
|
74
|
-
TypeGuard.
|
|
75
|
-
TypeGuard.
|
|
73
|
+
return (TypeGuard.IsUnknown(left) ? ExtendsResult.False :
|
|
74
|
+
TypeGuard.IsAny(left) ? ExtendsResult.Union :
|
|
75
|
+
TypeGuard.IsNever(left) ? ExtendsResult.True :
|
|
76
76
|
ExtendsResult.False);
|
|
77
77
|
}
|
|
78
78
|
// prettier-ignore
|
|
79
79
|
function TArray(left, right) {
|
|
80
|
-
return (TypeGuard.
|
|
80
|
+
return (TypeGuard.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True :
|
|
81
81
|
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
82
|
-
!TypeGuard.
|
|
82
|
+
!TypeGuard.IsArray(right) ? ExtendsResult.False :
|
|
83
83
|
IntoBooleanResult(Visit(left.items, right.items)));
|
|
84
84
|
}
|
|
85
85
|
// ------------------------------------------------------------------
|
|
@@ -88,7 +88,7 @@ function TArray(left, right) {
|
|
|
88
88
|
// prettier-ignore
|
|
89
89
|
function TAsyncIterator(left, right) {
|
|
90
90
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
91
|
-
!TypeGuard.
|
|
91
|
+
!TypeGuard.IsAsyncIterator(right) ? ExtendsResult.False :
|
|
92
92
|
IntoBooleanResult(Visit(left.items, right.items)));
|
|
93
93
|
}
|
|
94
94
|
// ------------------------------------------------------------------
|
|
@@ -97,9 +97,9 @@ function TAsyncIterator(left, right) {
|
|
|
97
97
|
// prettier-ignore
|
|
98
98
|
function TBigInt(left, right) {
|
|
99
99
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
100
|
-
TypeGuard.
|
|
101
|
-
TypeGuard.
|
|
102
|
-
TypeGuard.
|
|
100
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
101
|
+
TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
102
|
+
TypeGuard.IsBigInt(right) ? ExtendsResult.True :
|
|
103
103
|
ExtendsResult.False);
|
|
104
104
|
}
|
|
105
105
|
// ------------------------------------------------------------------
|
|
@@ -107,16 +107,16 @@ function TBigInt(left, right) {
|
|
|
107
107
|
// ------------------------------------------------------------------
|
|
108
108
|
// prettier-ignore
|
|
109
109
|
function TBooleanRight(left, right) {
|
|
110
|
-
return (TypeGuard.
|
|
111
|
-
TypeGuard.
|
|
110
|
+
return (TypeGuard.IsLiteralBoolean(left) ? ExtendsResult.True :
|
|
111
|
+
TypeGuard.IsBoolean(left) ? ExtendsResult.True :
|
|
112
112
|
ExtendsResult.False);
|
|
113
113
|
}
|
|
114
114
|
// prettier-ignore
|
|
115
115
|
function TBoolean(left, right) {
|
|
116
116
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
117
|
-
TypeGuard.
|
|
118
|
-
TypeGuard.
|
|
119
|
-
TypeGuard.
|
|
117
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
118
|
+
TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
119
|
+
TypeGuard.IsBoolean(right) ? ExtendsResult.True :
|
|
120
120
|
ExtendsResult.False);
|
|
121
121
|
}
|
|
122
122
|
// ------------------------------------------------------------------
|
|
@@ -125,8 +125,8 @@ function TBoolean(left, right) {
|
|
|
125
125
|
// prettier-ignore
|
|
126
126
|
function TConstructor(left, right) {
|
|
127
127
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
128
|
-
TypeGuard.
|
|
129
|
-
!TypeGuard.
|
|
128
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
129
|
+
!TypeGuard.IsConstructor(right) ? ExtendsResult.False :
|
|
130
130
|
left.parameters.length > right.parameters.length ? ExtendsResult.False :
|
|
131
131
|
(!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === ExtendsResult.True)) ? ExtendsResult.False :
|
|
132
132
|
IntoBooleanResult(Visit(left.returns, right.returns)));
|
|
@@ -137,9 +137,9 @@ function TConstructor(left, right) {
|
|
|
137
137
|
// prettier-ignore
|
|
138
138
|
function TDate(left, right) {
|
|
139
139
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
140
|
-
TypeGuard.
|
|
141
|
-
TypeGuard.
|
|
142
|
-
TypeGuard.
|
|
140
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
141
|
+
TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
142
|
+
TypeGuard.IsDate(right) ? ExtendsResult.True :
|
|
143
143
|
ExtendsResult.False);
|
|
144
144
|
}
|
|
145
145
|
// ------------------------------------------------------------------
|
|
@@ -148,8 +148,8 @@ function TDate(left, right) {
|
|
|
148
148
|
// prettier-ignore
|
|
149
149
|
function TFunction(left, right) {
|
|
150
150
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
151
|
-
TypeGuard.
|
|
152
|
-
!TypeGuard.
|
|
151
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
152
|
+
!TypeGuard.IsFunction(right) ? ExtendsResult.False :
|
|
153
153
|
left.parameters.length > right.parameters.length ? ExtendsResult.False :
|
|
154
154
|
(!left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === ExtendsResult.True)) ? ExtendsResult.False :
|
|
155
155
|
IntoBooleanResult(Visit(left.returns, right.returns)));
|
|
@@ -159,16 +159,16 @@ function TFunction(left, right) {
|
|
|
159
159
|
// ------------------------------------------------------------------
|
|
160
160
|
// prettier-ignore
|
|
161
161
|
function TIntegerRight(left, right) {
|
|
162
|
-
return (TypeGuard.
|
|
163
|
-
TypeGuard.
|
|
162
|
+
return (TypeGuard.IsLiteral(left) && ValueGuard.IsNumber(left.const) ? ExtendsResult.True :
|
|
163
|
+
TypeGuard.IsNumber(left) || TypeGuard.IsInteger(left) ? ExtendsResult.True :
|
|
164
164
|
ExtendsResult.False);
|
|
165
165
|
}
|
|
166
166
|
// prettier-ignore
|
|
167
167
|
function TInteger(left, right) {
|
|
168
|
-
return (TypeGuard.
|
|
168
|
+
return (TypeGuard.IsInteger(right) || TypeGuard.IsNumber(right) ? ExtendsResult.True :
|
|
169
169
|
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
170
|
-
TypeGuard.
|
|
171
|
-
TypeGuard.
|
|
170
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
171
|
+
TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
172
172
|
ExtendsResult.False);
|
|
173
173
|
}
|
|
174
174
|
// ------------------------------------------------------------------
|
|
@@ -192,7 +192,7 @@ function TIntersect(left, right) {
|
|
|
192
192
|
// prettier-ignore
|
|
193
193
|
function TIterator(left, right) {
|
|
194
194
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
195
|
-
!TypeGuard.
|
|
195
|
+
!TypeGuard.IsIterator(right) ? ExtendsResult.False :
|
|
196
196
|
IntoBooleanResult(Visit(left.items, right.items)));
|
|
197
197
|
}
|
|
198
198
|
// ------------------------------------------------------------------
|
|
@@ -200,14 +200,14 @@ function TIterator(left, right) {
|
|
|
200
200
|
// ------------------------------------------------------------------
|
|
201
201
|
// prettier-ignore
|
|
202
202
|
function TLiteral(left, right) {
|
|
203
|
-
return (TypeGuard.
|
|
203
|
+
return (TypeGuard.IsLiteral(right) && right.const === left.const ? ExtendsResult.True :
|
|
204
204
|
IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
205
|
-
TypeGuard.
|
|
206
|
-
TypeGuard.
|
|
207
|
-
TypeGuard.
|
|
208
|
-
TypeGuard.
|
|
209
|
-
TypeGuard.
|
|
210
|
-
TypeGuard.
|
|
205
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
206
|
+
TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
207
|
+
TypeGuard.IsString(right) ? TStringRight(left, right) :
|
|
208
|
+
TypeGuard.IsNumber(right) ? TNumberRight(left, right) :
|
|
209
|
+
TypeGuard.IsInteger(right) ? TIntegerRight(left, right) :
|
|
210
|
+
TypeGuard.IsBoolean(right) ? TBooleanRight(left, right) :
|
|
211
211
|
ExtendsResult.False);
|
|
212
212
|
}
|
|
213
213
|
// ------------------------------------------------------------------
|
|
@@ -228,7 +228,7 @@ function TNever(left, right) {
|
|
|
228
228
|
function UnwrapTNot(schema) {
|
|
229
229
|
let [current, depth] = [schema, 0];
|
|
230
230
|
while (true) {
|
|
231
|
-
if (!TypeGuard.
|
|
231
|
+
if (!TypeGuard.IsNot(current))
|
|
232
232
|
break;
|
|
233
233
|
current = current.not;
|
|
234
234
|
depth += 1;
|
|
@@ -241,8 +241,8 @@ function TNot(left, right) {
|
|
|
241
241
|
// type at runtime would put TypeBox at odds with TypeScripts ability to statically infer
|
|
242
242
|
// the type. Instead we unwrap to either unknown or T and continue evaluating.
|
|
243
243
|
// prettier-ignore
|
|
244
|
-
return (TypeGuard.
|
|
245
|
-
TypeGuard.
|
|
244
|
+
return (TypeGuard.IsNot(left) ? Visit(UnwrapTNot(left), right) :
|
|
245
|
+
TypeGuard.IsNot(right) ? Visit(left, UnwrapTNot(right)) :
|
|
246
246
|
Throw('Invalid fallthrough for Not'));
|
|
247
247
|
}
|
|
248
248
|
// ------------------------------------------------------------------
|
|
@@ -251,9 +251,9 @@ function TNot(left, right) {
|
|
|
251
251
|
// prettier-ignore
|
|
252
252
|
function TNull(left, right) {
|
|
253
253
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
254
|
-
TypeGuard.
|
|
255
|
-
TypeGuard.
|
|
256
|
-
TypeGuard.
|
|
254
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
255
|
+
TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
256
|
+
TypeGuard.IsNull(right) ? ExtendsResult.True :
|
|
257
257
|
ExtendsResult.False);
|
|
258
258
|
}
|
|
259
259
|
// ------------------------------------------------------------------
|
|
@@ -261,16 +261,16 @@ function TNull(left, right) {
|
|
|
261
261
|
// ------------------------------------------------------------------
|
|
262
262
|
// prettier-ignore
|
|
263
263
|
function TNumberRight(left, right) {
|
|
264
|
-
return (TypeGuard.
|
|
265
|
-
TypeGuard.
|
|
264
|
+
return (TypeGuard.IsLiteralNumber(left) ? ExtendsResult.True :
|
|
265
|
+
TypeGuard.IsNumber(left) || TypeGuard.IsInteger(left) ? ExtendsResult.True :
|
|
266
266
|
ExtendsResult.False);
|
|
267
267
|
}
|
|
268
268
|
// prettier-ignore
|
|
269
269
|
function TNumber(left, right) {
|
|
270
270
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
271
|
-
TypeGuard.
|
|
272
|
-
TypeGuard.
|
|
273
|
-
TypeGuard.
|
|
271
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
272
|
+
TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
273
|
+
TypeGuard.IsInteger(right) || TypeGuard.IsNumber(right) ? ExtendsResult.True :
|
|
274
274
|
ExtendsResult.False);
|
|
275
275
|
}
|
|
276
276
|
// ------------------------------------------------------------------
|
|
@@ -286,9 +286,9 @@ function IsObjectStringLike(schema) {
|
|
|
286
286
|
}
|
|
287
287
|
// prettier-ignore
|
|
288
288
|
function IsObjectSymbolLike(schema) {
|
|
289
|
-
return IsObjectPropertyCount(schema, 0) || (IsObjectPropertyCount(schema, 1) && 'description' in schema.properties && TypeGuard.
|
|
290
|
-
TypeGuard.
|
|
291
|
-
TypeGuard.
|
|
289
|
+
return IsObjectPropertyCount(schema, 0) || (IsObjectPropertyCount(schema, 1) && 'description' in schema.properties && TypeGuard.IsUnion(schema.properties.description) && schema.properties.description.anyOf.length === 2 && ((TypeGuard.IsString(schema.properties.description.anyOf[0]) &&
|
|
290
|
+
TypeGuard.IsUndefined(schema.properties.description.anyOf[1])) || (TypeGuard.IsString(schema.properties.description.anyOf[1]) &&
|
|
291
|
+
TypeGuard.IsUndefined(schema.properties.description.anyOf[0]))));
|
|
292
292
|
}
|
|
293
293
|
// prettier-ignore
|
|
294
294
|
function IsObjectNumberLike(schema) {
|
|
@@ -335,33 +335,33 @@ function IsObjectPromiseLike(schema) {
|
|
|
335
335
|
// prettier-ignore
|
|
336
336
|
function Property(left, right) {
|
|
337
337
|
return (Visit(left, right) === ExtendsResult.False ? ExtendsResult.False :
|
|
338
|
-
TypeGuard.
|
|
338
|
+
TypeGuard.IsOptional(left) && !TypeGuard.IsOptional(right) ? ExtendsResult.False :
|
|
339
339
|
ExtendsResult.True);
|
|
340
340
|
}
|
|
341
341
|
// prettier-ignore
|
|
342
342
|
function TObjectRight(left, right) {
|
|
343
|
-
return (TypeGuard.
|
|
344
|
-
TypeGuard.
|
|
345
|
-
(TypeGuard.
|
|
346
|
-
(TypeGuard.
|
|
347
|
-
(TypeGuard.
|
|
348
|
-
(TypeGuard.
|
|
349
|
-
(TypeGuard.
|
|
350
|
-
(TypeGuard.
|
|
351
|
-
(TypeGuard.
|
|
352
|
-
(TypeGuard.
|
|
353
|
-
(TypeGuard.
|
|
354
|
-
(TypeGuard.
|
|
355
|
-
(TypeGuard.
|
|
356
|
-
(TypeGuard.
|
|
357
|
-
(TypeGuard.
|
|
358
|
-
(TypeGuard.
|
|
359
|
-
(TypeGuard.
|
|
343
|
+
return (TypeGuard.IsUnknown(left) ? ExtendsResult.False :
|
|
344
|
+
TypeGuard.IsAny(left) ? ExtendsResult.Union : (TypeGuard.IsNever(left) ||
|
|
345
|
+
(TypeGuard.IsLiteralString(left) && IsObjectStringLike(right)) ||
|
|
346
|
+
(TypeGuard.IsLiteralNumber(left) && IsObjectNumberLike(right)) ||
|
|
347
|
+
(TypeGuard.IsLiteralBoolean(left) && IsObjectBooleanLike(right)) ||
|
|
348
|
+
(TypeGuard.IsSymbol(left) && IsObjectSymbolLike(right)) ||
|
|
349
|
+
(TypeGuard.IsBigInt(left) && IsObjectBigIntLike(right)) ||
|
|
350
|
+
(TypeGuard.IsString(left) && IsObjectStringLike(right)) ||
|
|
351
|
+
(TypeGuard.IsSymbol(left) && IsObjectSymbolLike(right)) ||
|
|
352
|
+
(TypeGuard.IsNumber(left) && IsObjectNumberLike(right)) ||
|
|
353
|
+
(TypeGuard.IsInteger(left) && IsObjectNumberLike(right)) ||
|
|
354
|
+
(TypeGuard.IsBoolean(left) && IsObjectBooleanLike(right)) ||
|
|
355
|
+
(TypeGuard.IsUint8Array(left) && IsObjectUint8ArrayLike(right)) ||
|
|
356
|
+
(TypeGuard.IsDate(left) && IsObjectDateLike(right)) ||
|
|
357
|
+
(TypeGuard.IsConstructor(left) && IsObjectConstructorLike(right)) ||
|
|
358
|
+
(TypeGuard.IsFunction(left) && IsObjectFunctionLike(right))) ? ExtendsResult.True :
|
|
359
|
+
(TypeGuard.IsRecord(left) && TypeGuard.IsString(RecordKey(left))) ? (() => {
|
|
360
360
|
// When expressing a Record with literal key values, the Record is converted into a Object with
|
|
361
361
|
// the Hint assigned as `Record`. This is used to invert the extends logic.
|
|
362
362
|
return right[Hint] === 'Record' ? ExtendsResult.True : ExtendsResult.False;
|
|
363
363
|
})() :
|
|
364
|
-
(TypeGuard.
|
|
364
|
+
(TypeGuard.IsRecord(left) && TypeGuard.IsNumber(RecordKey(left))) ? (() => {
|
|
365
365
|
return IsObjectPropertyCount(right, 0) ? ExtendsResult.True : ExtendsResult.False;
|
|
366
366
|
})() :
|
|
367
367
|
ExtendsResult.False);
|
|
@@ -369,14 +369,14 @@ function TObjectRight(left, right) {
|
|
|
369
369
|
// prettier-ignore
|
|
370
370
|
function TObject(left, right) {
|
|
371
371
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
372
|
-
TypeGuard.
|
|
373
|
-
!TypeGuard.
|
|
372
|
+
TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
373
|
+
!TypeGuard.IsObject(right) ? ExtendsResult.False :
|
|
374
374
|
(() => {
|
|
375
375
|
for (const key of Object.getOwnPropertyNames(right.properties)) {
|
|
376
|
-
if (!(key in left.properties) && !TypeGuard.
|
|
376
|
+
if (!(key in left.properties) && !TypeGuard.IsOptional(right.properties[key])) {
|
|
377
377
|
return ExtendsResult.False;
|
|
378
378
|
}
|
|
379
|
-
if (TypeGuard.
|
|
379
|
+
if (TypeGuard.IsOptional(right.properties[key])) {
|
|
380
380
|
return ExtendsResult.True;
|
|
381
381
|
}
|
|
382
382
|
if (Property(left.properties[key], right.properties[key]) === ExtendsResult.False) {
|
|
@@ -392,8 +392,8 @@ function TObject(left, right) {
|
|
|
392
392
|
// prettier-ignore
|
|
393
393
|
function TPromise(left, right) {
|
|
394
394
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
395
|
-
TypeGuard.
|
|
396
|
-
!TypeGuard.
|
|
395
|
+
TypeGuard.IsObject(right) && IsObjectPromiseLike(right) ? ExtendsResult.True :
|
|
396
|
+
!TypeGuard.IsPromise(right) ? ExtendsResult.False :
|
|
397
397
|
IntoBooleanResult(Visit(left.item, right.item)));
|
|
398
398
|
}
|
|
399
399
|
// ------------------------------------------------------------------
|
|
@@ -414,11 +414,11 @@ function RecordValue(schema) {
|
|
|
414
414
|
// prettier-ignore
|
|
415
415
|
function TRecordRight(left, right) {
|
|
416
416
|
const [Key, Value] = [RecordKey(right), RecordValue(right)];
|
|
417
|
-
return ((TypeGuard.
|
|
418
|
-
TypeGuard.
|
|
419
|
-
TypeGuard.
|
|
420
|
-
TypeGuard.
|
|
421
|
-
TypeGuard.
|
|
417
|
+
return ((TypeGuard.IsLiteralString(left) && TypeGuard.IsNumber(Key) && IntoBooleanResult(Visit(left, Value)) === ExtendsResult.True) ? ExtendsResult.True :
|
|
418
|
+
TypeGuard.IsUint8Array(left) && TypeGuard.IsNumber(Key) ? Visit(left, Value) :
|
|
419
|
+
TypeGuard.IsString(left) && TypeGuard.IsNumber(Key) ? Visit(left, Value) :
|
|
420
|
+
TypeGuard.IsArray(left) && TypeGuard.IsNumber(Key) ? Visit(left, Value) :
|
|
421
|
+
TypeGuard.IsObject(left) ? (() => {
|
|
422
422
|
for (const key of Object.getOwnPropertyNames(left.properties)) {
|
|
423
423
|
if (Property(Value, left.properties[key]) === ExtendsResult.False) {
|
|
424
424
|
return ExtendsResult.False;
|
|
@@ -431,8 +431,8 @@ function TRecordRight(left, right) {
|
|
|
431
431
|
// prettier-ignore
|
|
432
432
|
function TRecord(left, right) {
|
|
433
433
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
434
|
-
TypeGuard.
|
|
435
|
-
!TypeGuard.
|
|
434
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
435
|
+
!TypeGuard.IsRecord(right) ? ExtendsResult.False :
|
|
436
436
|
Visit(RecordValue(left), RecordValue(right)));
|
|
437
437
|
}
|
|
438
438
|
// ------------------------------------------------------------------
|
|
@@ -440,16 +440,16 @@ function TRecord(left, right) {
|
|
|
440
440
|
// ------------------------------------------------------------------
|
|
441
441
|
// prettier-ignore
|
|
442
442
|
function TStringRight(left, right) {
|
|
443
|
-
return (TypeGuard.
|
|
444
|
-
TypeGuard.
|
|
443
|
+
return (TypeGuard.IsLiteral(left) && ValueGuard.IsString(left.const) ? ExtendsResult.True :
|
|
444
|
+
TypeGuard.IsString(left) ? ExtendsResult.True :
|
|
445
445
|
ExtendsResult.False);
|
|
446
446
|
}
|
|
447
447
|
// prettier-ignore
|
|
448
448
|
function TString(left, right) {
|
|
449
449
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
450
|
-
TypeGuard.
|
|
451
|
-
TypeGuard.
|
|
452
|
-
TypeGuard.
|
|
450
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
451
|
+
TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
452
|
+
TypeGuard.IsString(right) ? ExtendsResult.True :
|
|
453
453
|
ExtendsResult.False);
|
|
454
454
|
}
|
|
455
455
|
// ------------------------------------------------------------------
|
|
@@ -458,9 +458,9 @@ function TString(left, right) {
|
|
|
458
458
|
// prettier-ignore
|
|
459
459
|
function TSymbol(left, right) {
|
|
460
460
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
461
|
-
TypeGuard.
|
|
462
|
-
TypeGuard.
|
|
463
|
-
TypeGuard.
|
|
461
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
462
|
+
TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
463
|
+
TypeGuard.IsSymbol(right) ? ExtendsResult.True :
|
|
464
464
|
ExtendsResult.False);
|
|
465
465
|
}
|
|
466
466
|
// ------------------------------------------------------------------
|
|
@@ -471,8 +471,8 @@ function TTemplateLiteral(left, right) {
|
|
|
471
471
|
// TemplateLiteral types are resolved to either unions for finite expressions or string
|
|
472
472
|
// for infinite expressions. Here we call to TemplateLiteralResolver to resolve for
|
|
473
473
|
// either type and continue evaluating.
|
|
474
|
-
return (TypeGuard.
|
|
475
|
-
TypeGuard.
|
|
474
|
+
return (TypeGuard.IsTemplateLiteral(left) ? Visit(TemplateLiteralToUnion(left), right) :
|
|
475
|
+
TypeGuard.IsTemplateLiteral(right) ? Visit(left, TemplateLiteralToUnion(right)) :
|
|
476
476
|
Throw('Invalid fallthrough for TemplateLiteral'));
|
|
477
477
|
}
|
|
478
478
|
// ------------------------------------------------------------------
|
|
@@ -480,23 +480,23 @@ function TTemplateLiteral(left, right) {
|
|
|
480
480
|
// ------------------------------------------------------------------
|
|
481
481
|
// prettier-ignore
|
|
482
482
|
function IsArrayOfTuple(left, right) {
|
|
483
|
-
return (TypeGuard.
|
|
483
|
+
return (TypeGuard.IsArray(right) &&
|
|
484
484
|
left.items !== undefined &&
|
|
485
485
|
left.items.every((schema) => Visit(schema, right.items) === ExtendsResult.True));
|
|
486
486
|
}
|
|
487
487
|
// prettier-ignore
|
|
488
488
|
function TTupleRight(left, right) {
|
|
489
|
-
return (TypeGuard.
|
|
490
|
-
TypeGuard.
|
|
491
|
-
TypeGuard.
|
|
489
|
+
return (TypeGuard.IsNever(left) ? ExtendsResult.True :
|
|
490
|
+
TypeGuard.IsUnknown(left) ? ExtendsResult.False :
|
|
491
|
+
TypeGuard.IsAny(left) ? ExtendsResult.Union :
|
|
492
492
|
ExtendsResult.False);
|
|
493
493
|
}
|
|
494
494
|
// prettier-ignore
|
|
495
495
|
function TTuple(left, right) {
|
|
496
496
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
497
|
-
TypeGuard.
|
|
498
|
-
TypeGuard.
|
|
499
|
-
!TypeGuard.
|
|
497
|
+
TypeGuard.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True :
|
|
498
|
+
TypeGuard.IsArray(right) && IsArrayOfTuple(left, right) ? ExtendsResult.True :
|
|
499
|
+
!TypeGuard.IsTuple(right) ? ExtendsResult.False :
|
|
500
500
|
(ValueGuard.IsUndefined(left.items) && !ValueGuard.IsUndefined(right.items)) || (!ValueGuard.IsUndefined(left.items) && ValueGuard.IsUndefined(right.items)) ? ExtendsResult.False :
|
|
501
501
|
(ValueGuard.IsUndefined(left.items) && !ValueGuard.IsUndefined(right.items)) ? ExtendsResult.True :
|
|
502
502
|
left.items.every((schema, index) => Visit(schema, right.items[index]) === ExtendsResult.True) ? ExtendsResult.True :
|
|
@@ -508,9 +508,9 @@ function TTuple(left, right) {
|
|
|
508
508
|
// prettier-ignore
|
|
509
509
|
function TUint8Array(left, right) {
|
|
510
510
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
511
|
-
TypeGuard.
|
|
512
|
-
TypeGuard.
|
|
513
|
-
TypeGuard.
|
|
511
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
512
|
+
TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
513
|
+
TypeGuard.IsUint8Array(right) ? ExtendsResult.True :
|
|
514
514
|
ExtendsResult.False);
|
|
515
515
|
}
|
|
516
516
|
// ------------------------------------------------------------------
|
|
@@ -519,10 +519,10 @@ function TUint8Array(left, right) {
|
|
|
519
519
|
// prettier-ignore
|
|
520
520
|
function TUndefined(left, right) {
|
|
521
521
|
return (IsStructuralRight(right) ? StructuralRight(left, right) :
|
|
522
|
-
TypeGuard.
|
|
523
|
-
TypeGuard.
|
|
524
|
-
TypeGuard.
|
|
525
|
-
TypeGuard.
|
|
522
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
523
|
+
TypeGuard.IsRecord(right) ? TRecordRight(left, right) :
|
|
524
|
+
TypeGuard.IsVoid(right) ? VoidRight(left, right) :
|
|
525
|
+
TypeGuard.IsUndefined(right) ? ExtendsResult.True :
|
|
526
526
|
ExtendsResult.False);
|
|
527
527
|
}
|
|
528
528
|
// ------------------------------------------------------------------
|
|
@@ -549,18 +549,18 @@ function TUnknownRight(left, right) {
|
|
|
549
549
|
}
|
|
550
550
|
// prettier-ignore
|
|
551
551
|
function TUnknown(left, right) {
|
|
552
|
-
return (TypeGuard.
|
|
553
|
-
TypeGuard.
|
|
554
|
-
TypeGuard.
|
|
555
|
-
TypeGuard.
|
|
556
|
-
TypeGuard.
|
|
557
|
-
TypeGuard.
|
|
558
|
-
TypeGuard.
|
|
559
|
-
TypeGuard.
|
|
560
|
-
TypeGuard.
|
|
561
|
-
TypeGuard.
|
|
562
|
-
TypeGuard.
|
|
563
|
-
TypeGuard.
|
|
552
|
+
return (TypeGuard.IsNever(right) ? TNeverRight(left, right) :
|
|
553
|
+
TypeGuard.IsIntersect(right) ? TIntersectRight(left, right) :
|
|
554
|
+
TypeGuard.IsUnion(right) ? TUnionRight(left, right) :
|
|
555
|
+
TypeGuard.IsAny(right) ? TAnyRight(left, right) :
|
|
556
|
+
TypeGuard.IsString(right) ? TStringRight(left, right) :
|
|
557
|
+
TypeGuard.IsNumber(right) ? TNumberRight(left, right) :
|
|
558
|
+
TypeGuard.IsInteger(right) ? TIntegerRight(left, right) :
|
|
559
|
+
TypeGuard.IsBoolean(right) ? TBooleanRight(left, right) :
|
|
560
|
+
TypeGuard.IsArray(right) ? TArrayRight(left, right) :
|
|
561
|
+
TypeGuard.IsTuple(right) ? TTupleRight(left, right) :
|
|
562
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
563
|
+
TypeGuard.IsUnknown(right) ? ExtendsResult.True :
|
|
564
564
|
ExtendsResult.False);
|
|
565
565
|
}
|
|
566
566
|
// ------------------------------------------------------------------
|
|
@@ -568,53 +568,53 @@ function TUnknown(left, right) {
|
|
|
568
568
|
// ------------------------------------------------------------------
|
|
569
569
|
// prettier-ignore
|
|
570
570
|
function VoidRight(left, right) {
|
|
571
|
-
return (TypeGuard.
|
|
572
|
-
TypeGuard.
|
|
571
|
+
return (TypeGuard.IsUndefined(left) ? ExtendsResult.True :
|
|
572
|
+
TypeGuard.IsUndefined(left) ? ExtendsResult.True :
|
|
573
573
|
ExtendsResult.False);
|
|
574
574
|
}
|
|
575
575
|
// prettier-ignore
|
|
576
576
|
function TVoid(left, right) {
|
|
577
|
-
return (TypeGuard.
|
|
578
|
-
TypeGuard.
|
|
579
|
-
TypeGuard.
|
|
580
|
-
TypeGuard.
|
|
581
|
-
TypeGuard.
|
|
582
|
-
TypeGuard.
|
|
577
|
+
return (TypeGuard.IsIntersect(right) ? TIntersectRight(left, right) :
|
|
578
|
+
TypeGuard.IsUnion(right) ? TUnionRight(left, right) :
|
|
579
|
+
TypeGuard.IsUnknown(right) ? TUnknownRight(left, right) :
|
|
580
|
+
TypeGuard.IsAny(right) ? TAnyRight(left, right) :
|
|
581
|
+
TypeGuard.IsObject(right) ? TObjectRight(left, right) :
|
|
582
|
+
TypeGuard.IsVoid(right) ? ExtendsResult.True :
|
|
583
583
|
ExtendsResult.False);
|
|
584
584
|
}
|
|
585
585
|
// prettier-ignore
|
|
586
586
|
function Visit(left, right) {
|
|
587
587
|
return (
|
|
588
588
|
// resolvable
|
|
589
|
-
(TypeGuard.
|
|
590
|
-
(TypeGuard.
|
|
589
|
+
(TypeGuard.IsTemplateLiteral(left) || TypeGuard.IsTemplateLiteral(right)) ? TTemplateLiteral(left, right) :
|
|
590
|
+
(TypeGuard.IsNot(left) || TypeGuard.IsNot(right)) ? TNot(left, right) :
|
|
591
591
|
// standard
|
|
592
|
-
TypeGuard.
|
|
593
|
-
TypeGuard.
|
|
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.
|
|
592
|
+
TypeGuard.IsAny(left) ? TAny(left, right) :
|
|
593
|
+
TypeGuard.IsArray(left) ? TArray(left, right) :
|
|
594
|
+
TypeGuard.IsBigInt(left) ? TBigInt(left, right) :
|
|
595
|
+
TypeGuard.IsBoolean(left) ? TBoolean(left, right) :
|
|
596
|
+
TypeGuard.IsAsyncIterator(left) ? TAsyncIterator(left, right) :
|
|
597
|
+
TypeGuard.IsConstructor(left) ? TConstructor(left, right) :
|
|
598
|
+
TypeGuard.IsDate(left) ? TDate(left, right) :
|
|
599
|
+
TypeGuard.IsFunction(left) ? TFunction(left, right) :
|
|
600
|
+
TypeGuard.IsInteger(left) ? TInteger(left, right) :
|
|
601
|
+
TypeGuard.IsIntersect(left) ? TIntersect(left, right) :
|
|
602
|
+
TypeGuard.IsIterator(left) ? TIterator(left, right) :
|
|
603
|
+
TypeGuard.IsLiteral(left) ? TLiteral(left, right) :
|
|
604
|
+
TypeGuard.IsNever(left) ? TNever(left, right) :
|
|
605
|
+
TypeGuard.IsNull(left) ? TNull(left, right) :
|
|
606
|
+
TypeGuard.IsNumber(left) ? TNumber(left, right) :
|
|
607
|
+
TypeGuard.IsObject(left) ? TObject(left, right) :
|
|
608
|
+
TypeGuard.IsRecord(left) ? TRecord(left, right) :
|
|
609
|
+
TypeGuard.IsString(left) ? TString(left, right) :
|
|
610
|
+
TypeGuard.IsSymbol(left) ? TSymbol(left, right) :
|
|
611
|
+
TypeGuard.IsTuple(left) ? TTuple(left, right) :
|
|
612
|
+
TypeGuard.IsPromise(left) ? TPromise(left, right) :
|
|
613
|
+
TypeGuard.IsUint8Array(left) ? TUint8Array(left, right) :
|
|
614
|
+
TypeGuard.IsUndefined(left) ? TUndefined(left, right) :
|
|
615
|
+
TypeGuard.IsUnion(left) ? TUnion(left, right) :
|
|
616
|
+
TypeGuard.IsUnknown(left) ? TUnknown(left, right) :
|
|
617
|
+
TypeGuard.IsVoid(left) ? TVoid(left, right) :
|
|
618
618
|
Throw(`Unknown left type operand '${left[Kind]}'`));
|
|
619
619
|
}
|
|
620
620
|
export function ExtendsCheck(left, right) {
|
|
@@ -7,7 +7,7 @@ import { ExtendsFromMappedResult } from './extends-from-mapped-result.mjs';
|
|
|
7
7
|
// TypeGuard
|
|
8
8
|
// ------------------------------------------------------------------
|
|
9
9
|
// prettier-ignore
|
|
10
|
-
import {
|
|
10
|
+
import { IsMappedKey, IsMappedResult } from '../guard/type.mjs';
|
|
11
11
|
// prettier-ignore
|
|
12
12
|
function ExtendsResolve(left, right, trueType, falseType) {
|
|
13
13
|
const R = ExtendsCheck(left, right);
|
|
@@ -18,7 +18,7 @@ function ExtendsResolve(left, right, trueType, falseType) {
|
|
|
18
18
|
/** `[Json]` Creates a Conditional type */
|
|
19
19
|
export function Extends(L, R, T, F, options = {}) {
|
|
20
20
|
// prettier-ignore
|
|
21
|
-
return (
|
|
22
|
-
|
|
21
|
+
return (IsMappedResult(L) ? ExtendsFromMappedResult(L, R, T, F, options) :
|
|
22
|
+
IsMappedKey(L) ? CloneType(ExtendsFromMappedKey(L, R, T, F, options)) :
|
|
23
23
|
CloneType(ExtendsResolve(L, R, T, F), options));
|
|
24
24
|
}
|