@sinclair/typebox 0.21.1 → 0.21.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.
Files changed (2) hide show
  1. package/package.json +6 -2
  2. package/typebox.d.ts +6 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.21.1",
3
+ "version": "0.21.2",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "json-schema",
@@ -20,7 +20,10 @@
20
20
  "clean": "hammer task clean",
21
21
  "build": "hammer task build",
22
22
  "example": "hammer task example",
23
- "test": "hammer task spec"
23
+ "spec": "hammer task spec",
24
+ "spec:types": "hammer task spec_types",
25
+ "spec:schemas": "hammer task spec_schemas",
26
+ "test": "npm run spec"
24
27
  },
25
28
  "devDependencies": {
26
29
  "@sinclair/hammer": "^0.15.7",
@@ -31,6 +34,7 @@
31
34
  "ajv-formats": "^2.0.2",
32
35
  "chai": "^4.3.4",
33
36
  "mocha": "^9.1.2",
37
+ "tsd": "^0.19.0",
34
38
  "typescript": "^4.5.2"
35
39
  }
36
40
  }
package/typebox.d.ts CHANGED
@@ -190,6 +190,10 @@ export declare type TVoid = Infer<void> & {
190
190
  } & CustomOptions;
191
191
  export declare type TSchema = TIntersect<any> | TUnion<any> | TTuple<any> | TObject<any> | TKeyOf<any> | TRecord<any> | TArray<any> | TEnum<any> | TLiteral<any> | TString | TNumber | TInteger | TBoolean | TNull | TUnknown | TAny | TConstructor<any> | TFunction<any> | TPromise<any> | TUndefined | TVoid;
192
192
  export declare type UnionToIntersect<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
193
+ export declare type IntersectEvaluate<T extends readonly TSchema[]> = {
194
+ [K in keyof T]: Static<T[K]>;
195
+ };
196
+ export declare type IntersectReduce<I extends unknown, T extends readonly any[]> = T extends [infer A, ...infer B] ? IntersectReduce<I & A, B> : I;
193
197
  export declare type ReadonlyOptionalPropertyKeys<T extends TProperties> = {
194
198
  [K in keyof T]: T[K] extends TReadonlyOptional<TSchema> ? K : never;
195
199
  }[keyof T];
@@ -209,9 +213,10 @@ export declare type StaticProperties<T extends TProperties> = {
209
213
  } & {
210
214
  [K in RequiredPropertyKeys<T>]: Static<T[K]>;
211
215
  };
216
+ export declare type StaticRecord<K extends TRecordKey, T extends TSchema> = K extends TString ? Record<string, Static<T>> : K extends TNumber ? Record<number, Static<T>> : K extends TKeyOf<any> ? Record<K['_infer'], Static<T>> : K extends TUnion<any> ? Record<K['_infer'], Static<T>> : never;
212
217
  export declare type StaticEnum<T> = T extends TEnumKey<infer U>[] ? U : never;
213
218
  export declare type StaticKeyOf<T extends TKey[]> = T extends Array<infer K> ? K : never;
214
- export declare type StaticIntersect<T extends readonly TSchema[]> = UnionToIntersect<StaticUnion<T>>;
219
+ export declare type StaticIntersect<T extends readonly TSchema[]> = IntersectReduce<unknown, IntersectEvaluate<T>>;
215
220
  export declare type StaticUnion<T extends readonly TSchema[]> = {
216
221
  [K in keyof T]: Static<T[K]>;
217
222
  }[number];
@@ -219,7 +224,6 @@ export declare type StaticTuple<T extends readonly TSchema[]> = {
219
224
  [K in keyof T]: Static<T[K]>;
220
225
  };
221
226
  export declare type StaticObject<T extends TProperties> = StaticProperties<StaticProperties<T>>;
222
- export declare type StaticRecord<K extends TRecordKey, T extends TSchema> = K extends TString ? Record<string, Static<T>> : K extends TNumber ? Record<number, Static<T>> : K extends TKeyOf<any> ? Record<K['_infer'], Static<T>> : K extends TUnion<any> ? Record<K['_infer'], Static<T>> : never;
223
227
  export declare type StaticArray<T extends TSchema> = Array<Static<T>>;
224
228
  export declare type StaticLiteral<T extends TValue> = T;
225
229
  export declare type StaticConstructor<T extends readonly TSchema[], U extends TSchema> = new (...args: [...{