@sinclair/typebox 0.27.5 → 0.27.6
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/package.json +1 -1
- package/readme.md +1 -1
- package/typebox.d.ts +3 -3
- package/value/create.js +8 -2
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -402,7 +402,7 @@ The following table lists the Standard TypeBox types. These types are fully comp
|
|
|
402
402
|
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
403
403
|
│ const T = Type.Record( │ type T = Record< │ const T = { │
|
|
404
404
|
│ Type.String(), │ string, │ type: 'object', │
|
|
405
|
-
│ Type.Number() │ number
|
|
405
|
+
│ Type.Number() │ number │ patternProperties: { │
|
|
406
406
|
│ ) │ > │ '^.*$': { │
|
|
407
407
|
│ │ │ type: 'number' │
|
|
408
408
|
│ │ │ } │
|
package/typebox.d.ts
CHANGED
|
@@ -183,7 +183,7 @@ export type TKeyOfTuple<T extends TSchema> = {
|
|
|
183
183
|
} extends infer U ? UnionToTuple<Exclude<{
|
|
184
184
|
[K in keyof U]: U[K];
|
|
185
185
|
}[keyof U], undefined>> : never;
|
|
186
|
-
export type TKeyOf<T extends TSchema = TSchema> = (T extends TComposite ? TKeyOfTuple<T> : T extends TIntersect ? TKeyOfTuple<T> : T extends TUnion ? TKeyOfTuple<T> : T extends TObject ? TKeyOfTuple<T> : T extends TRecord<infer K> ? [K] : [
|
|
186
|
+
export type TKeyOf<T extends TSchema = TSchema> = (T extends TComposite ? TKeyOfTuple<T> : T extends TIntersect ? TKeyOfTuple<T> : T extends TUnion ? TKeyOfTuple<T> : T extends TObject ? TKeyOfTuple<T> : T extends TRecursive<infer S> ? TKeyOfTuple<S> : T extends TRecord<infer K> ? [K] : [
|
|
187
187
|
]) extends infer R ? TUnionResult<Assert<R, TSchema[]>> : never;
|
|
188
188
|
export type TLiteralValue = string | number | boolean;
|
|
189
189
|
export interface TLiteral<T extends TLiteralValue = TLiteralValue> extends TSchema {
|
|
@@ -248,7 +248,7 @@ export type TOmitArray<T extends TSchema[], K extends keyof any> = Assert<{
|
|
|
248
248
|
[K2 in keyof T]: TOmit<Assert<T[K2], TSchema>, K>;
|
|
249
249
|
}, TSchema[]>;
|
|
250
250
|
export type TOmitProperties<T extends TProperties, K extends keyof any> = Evaluate<Assert<Omit<T, K>, TProperties>>;
|
|
251
|
-
export type TOmit<T extends TSchema, K extends keyof any> = T extends TComposite<infer S> ? TComposite<TOmitArray<S, K>> : T extends TIntersect<infer S> ? TIntersect<TOmitArray<S, K>> : T extends TUnion<infer S> ? TUnion<TOmitArray<S, K>> : T extends TObject<infer S> ? TObject<TOmitProperties<S, K>> : T;
|
|
251
|
+
export type TOmit<T extends TSchema = TSchema, K extends keyof any = keyof any> = T extends TComposite<infer S> ? TComposite<TOmitArray<S, K>> : T extends TIntersect<infer S> ? TIntersect<TOmitArray<S, K>> : T extends TUnion<infer S> ? TUnion<TOmitArray<S, K>> : T extends TObject<infer S> ? TObject<TOmitProperties<S, K>> : T;
|
|
252
252
|
export type TParameters<T extends TFunction> = TTuple<T['parameters']>;
|
|
253
253
|
export type TPartialObjectArray<T extends TObject[]> = Assert<{
|
|
254
254
|
[K in keyof T]: TPartial<Assert<T[K], TObject>>;
|
|
@@ -266,7 +266,7 @@ export type TPickArray<T extends TSchema[], K extends keyof any> = {
|
|
|
266
266
|
export type TPickProperties<T extends TProperties, K extends keyof any> = Pick<T, Assert<Extract<K, keyof T>, keyof T>> extends infer R ? ({
|
|
267
267
|
[K in keyof R]: Assert<R[K], TSchema> extends TSchema ? R[K] : never;
|
|
268
268
|
}) : never;
|
|
269
|
-
export type TPick<T extends TSchema, K extends keyof any> = T extends TComposite<infer S> ? TComposite<TPickArray<S, K>> : T extends TIntersect<infer S> ? TIntersect<TPickArray<S, K>> : T extends TUnion<infer S> ? TUnion<TPickArray<S, K>> : T extends TObject<infer S> ? TObject<TPickProperties<S, K>> : T;
|
|
269
|
+
export type TPick<T extends TSchema = TSchema, K extends keyof any = keyof any> = T extends TComposite<infer S> ? TComposite<TPickArray<S, K>> : T extends TIntersect<infer S> ? TIntersect<TPickArray<S, K>> : T extends TUnion<infer S> ? TUnion<TPickArray<S, K>> : T extends TObject<infer S> ? TObject<TPickProperties<S, K>> : T;
|
|
270
270
|
export interface TPromise<T extends TSchema = TSchema> extends TSchema {
|
|
271
271
|
[Kind]: 'Promise';
|
|
272
272
|
static: Promise<Static<T, this['params']>>;
|
package/value/create.js
CHANGED
|
@@ -49,7 +49,7 @@ class ValueCreateNeverTypeError extends Error {
|
|
|
49
49
|
exports.ValueCreateNeverTypeError = ValueCreateNeverTypeError;
|
|
50
50
|
class ValueCreateIntersectTypeError extends Error {
|
|
51
51
|
constructor(schema) {
|
|
52
|
-
super('ValueCreate:
|
|
52
|
+
super('ValueCreate: Intersect produced invalid value. Consider using a default value.');
|
|
53
53
|
this.schema = schema;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -179,7 +179,13 @@ var ValueCreate;
|
|
|
179
179
|
return schema.default;
|
|
180
180
|
}
|
|
181
181
|
else {
|
|
182
|
-
|
|
182
|
+
// Note: The best we can do here is attempt to instance each sub type and apply through object assign. For non-object
|
|
183
|
+
// sub types, we just escape the assignment and just return the value. In the latter case, this is typically going to
|
|
184
|
+
// be a consequence of an illogical intersection.
|
|
185
|
+
const value = schema.allOf.reduce((acc, schema) => {
|
|
186
|
+
const next = Visit(schema, references);
|
|
187
|
+
return typeof next === 'object' ? { ...acc, ...next } : next;
|
|
188
|
+
}, {});
|
|
183
189
|
if (!check_1.ValueCheck.Check(schema, references, value))
|
|
184
190
|
throw new ValueCreateIntersectTypeError(schema);
|
|
185
191
|
return value;
|