@sinclair/typebox 0.30.0-dev-5 → 0.30.0-dev-7

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 (3) hide show
  1. package/package.json +1 -1
  2. package/typebox.d.ts +79 -63
  3. package/typebox.js +42 -38
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.30.0-dev-5",
3
+ "version": "0.30.0-dev-7",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/typebox.d.ts CHANGED
@@ -43,7 +43,6 @@ export type IntersectType<T extends TSchema[]> = T extends [] ? TNever : T exten
43
43
  export type UnionOptional<T extends TSchema[]> = T extends [infer L, ...infer R] ? L extends (TOptional<AssertType<L>>) ? true : UnionOptional<AssertRest<R>> : false;
44
44
  export type UnionResolve<T extends TSchema[], U = OptionalUnwrapRest<AssertRest<T>>> = UnionOptional<AssertRest<T>> extends true ? TOptional<TUnion<AssertRest<U>>> : TUnion<AssertRest<U>>;
45
45
  export type UnionType<T extends TSchema[]> = T extends [] ? TNever : T extends [TSchema] ? AssertType<T[0]> : UnionResolve<T>;
46
- export type Key = string | number;
47
46
  export interface SchemaOptions {
48
47
  $schema?: string;
49
48
  /** Id for this schema */
@@ -85,12 +84,18 @@ export interface TAny extends TSchema {
85
84
  static: any;
86
85
  }
87
86
  export interface ArrayOptions extends SchemaOptions {
87
+ /** The minimum number of items in this array */
88
88
  minItems?: number;
89
+ /** The maximum number of items in this array */
89
90
  maxItems?: number;
91
+ /** Should this schema contain unique items */
92
+ uniqueItems?: boolean;
93
+ /** A schema for which some elements should match */
90
94
  contains?: TSchema;
95
+ /** A minimum number of contains schema matches */
91
96
  minContains?: number;
97
+ /** A maximum number of contains schema matches */
92
98
  maxContains?: number;
93
- uniqueItems?: boolean;
94
99
  }
95
100
  export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptions {
96
101
  [Kind]: 'Array';
@@ -135,9 +140,13 @@ export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema
135
140
  returns: U;
136
141
  }
137
142
  export interface DateOptions extends SchemaOptions {
143
+ /** The exclusive maximum timestamp value */
138
144
  exclusiveMaximumTimestamp?: number;
145
+ /** The exclusive minimum timestamp value */
139
146
  exclusiveMinimumTimestamp?: number;
147
+ /** The maximum timestamp value */
140
148
  maximumTimestamp?: number;
149
+ /** The minimum timestamp value */
141
150
  minimumTimestamp?: number;
142
151
  }
143
152
  export interface TDate extends TSchema, DateOptions {
@@ -181,14 +190,14 @@ export interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema =
181
190
  parameters: T;
182
191
  returns: U;
183
192
  }
184
- export type TIndexRest<T extends TSchema[], K extends Key> = T extends [infer L, ...infer R] ? [TIndexType<AssertType<L>, K>, ...TIndexRest<AssertRest<R>, K>] : [];
185
- export type TIndexProperty<T extends TProperties, K extends Key> = K extends keyof T ? [T[K]] : [];
186
- export type TIndexTuple<T extends TSchema[], K extends Key> = K extends keyof T ? [T[K]] : [];
187
- export type TIndexType<T extends TSchema, K extends Key> = T extends TRecursive<infer S> ? TIndexType<S, K> : T extends TIntersect<infer S> ? IntersectType<AssertRest<Discard<Flat<TIndexRest<S, K>>, TNever>>> : T extends TUnion<infer S> ? UnionType<AssertRest<Flat<TIndexRest<S, K>>>> : T extends TObject<infer S> ? UnionType<AssertRest<Flat<TIndexProperty<S, K>>>> : T extends TTuple<infer S> ? UnionType<AssertRest<Flat<TIndexTuple<S, K>>>> : [
193
+ export type TIndexRest<T extends TSchema[], K extends TPropertyKey> = T extends [infer L, ...infer R] ? [TIndexType<AssertType<L>, K>, ...TIndexRest<AssertRest<R>, K>] : [];
194
+ export type TIndexProperty<T extends TProperties, K extends TPropertyKey> = K extends keyof T ? [T[K]] : [];
195
+ export type TIndexTuple<T extends TSchema[], K extends TPropertyKey> = K extends keyof T ? [T[K]] : [];
196
+ export type TIndexType<T extends TSchema, K extends TPropertyKey> = T extends TRecursive<infer S> ? TIndexType<S, K> : T extends TIntersect<infer S> ? IntersectType<AssertRest<Discard<Flat<TIndexRest<S, K>>, TNever>>> : T extends TUnion<infer S> ? UnionType<AssertRest<Flat<TIndexRest<S, K>>>> : T extends TObject<infer S> ? UnionType<AssertRest<Flat<TIndexProperty<S, K>>>> : T extends TTuple<infer S> ? UnionType<AssertRest<Flat<TIndexTuple<S, K>>>> : [
188
197
  ];
189
- export type TIndexRestMany<T extends TSchema, K extends Key[]> = K extends [infer L, ...infer R] ? [TIndexType<T, Assert<L, Key>>, ...TIndexRestMany<T, Assert<R, Key[]>>] : [
198
+ export type TIndexRestMany<T extends TSchema, K extends TPropertyKey[]> = K extends [infer L, ...infer R] ? [TIndexType<T, Assert<L, TPropertyKey>>, ...TIndexRestMany<T, Assert<R, TPropertyKey[]>>] : [
190
199
  ];
191
- export type TIndex<T extends TSchema, K extends Key[]> = T extends TRecursive<infer S> ? TIndex<S, K> : T extends TIntersect ? UnionType<Flat<TIndexRestMany<T, K>>> : T extends TUnion ? UnionType<Flat<TIndexRestMany<T, K>>> : T extends TObject ? UnionType<Flat<TIndexRestMany<T, K>>> : T extends TTuple ? UnionType<Flat<TIndexRestMany<T, K>>> : TNever;
200
+ export type TIndex<T extends TSchema, K extends TPropertyKey[]> = T extends TRecursive<infer S> ? TIndex<S, K> : T extends TIntersect ? UnionType<Flat<TIndexRestMany<T, K>>> : T extends TUnion ? UnionType<Flat<TIndexRestMany<T, K>>> : T extends TObject ? UnionType<Flat<TIndexRestMany<T, K>>> : T extends TTuple ? UnionType<Flat<TIndexRestMany<T, K>>> : TNever;
192
201
  export interface TInteger extends TSchema, NumericOptions<number> {
193
202
  [Kind]: 'Integer';
194
203
  static: number;
@@ -261,7 +270,8 @@ export type PropertiesReducer<T extends TProperties, R extends Record<keyof any,
261
270
  export type PropertiesReduce<T extends TProperties, P extends unknown[]> = PropertiesReducer<T, {
262
271
  [K in keyof T]: Static<T[K], P>;
263
272
  }>;
264
- export type TProperties = Record<keyof any, TSchema>;
273
+ export type TPropertyKey = string | number;
274
+ export type TProperties = Record<TPropertyKey, TSchema>;
265
275
  export type ObjectProperties<T> = T extends TObject<infer U> ? U : never;
266
276
  export type ObjectPropertyKeys<T> = T extends TObject<infer U> ? keyof U : never;
267
277
  export type TAdditionalProperties = undefined | TSchema | boolean;
@@ -287,13 +297,13 @@ export type TParameters<T extends TFunction> = Ensure<TTuple<T['parameters']>>;
287
297
  export type TPartialObjectArray<T extends TObject[]> = AssertRest<{
288
298
  [K in keyof T]: TPartial<AssertType<T[K], TObject>>;
289
299
  }, TObject[]>;
290
- export type TPartialArray<T extends TSchema[]> = AssertRest<{
300
+ export type TPartialRest<T extends TSchema[]> = AssertRest<{
291
301
  [K in keyof T]: TPartial<AssertType<T[K]>>;
292
302
  }>;
293
303
  export type TPartialProperties<T extends TProperties> = Evaluate<AssertProperties<{
294
304
  [K in keyof T]: TOptional<T[K]>;
295
305
  }>>;
296
- export type TPartial<T extends TSchema> = T extends TRecursive<infer S> ? TRecursive<TPartial<S>> : T extends TIntersect<infer S> ? TIntersect<TPartialArray<S>> : T extends TUnion<infer S> ? TUnion<TPartialArray<S>> : T extends TObject<infer S> ? TObject<TPartialProperties<S>> : T;
306
+ export type TPartial<T extends TSchema> = T extends TRecursive<infer S> ? TRecursive<TPartial<S>> : T extends TIntersect<infer S> ? TIntersect<TPartialRest<S>> : T extends TUnion<infer S> ? TUnion<TPartialRest<S>> : T extends TObject<infer S> ? TObject<TPartialProperties<S>> : T;
297
307
  export type TPickProperties<T extends TProperties, K extends keyof any> = Pick<T, Assert<Extract<K, keyof T>, keyof T>> extends infer R ? ({
298
308
  [K in keyof R]: AssertType<R[K]> extends TSchema ? R[K] : never;
299
309
  }) : never;
@@ -346,21 +356,27 @@ export interface TRef<T extends TSchema = TSchema> extends TSchema {
346
356
  }
347
357
  export type TRest<T extends TSchema> = T extends TTuple<infer R> ? Assert<R, TSchema[]> : Assert<[T], TSchema[]>;
348
358
  export type TReturnType<T extends TFunction> = T['returns'];
349
- export type TRequiredArray<T extends TSchema[]> = AssertRest<{
359
+ export type TRequiredRest<T extends TSchema[]> = AssertRest<{
350
360
  [K in keyof T]: TRequired<AssertType<T[K]>>;
351
361
  }>;
352
362
  export type TRequiredProperties<T extends TProperties> = Evaluate<AssertProperties<{
353
363
  [K in keyof T]: T[K] extends TOptional<infer S> ? S : T[K];
354
364
  }>>;
355
- export type TRequired<T extends TSchema> = T extends TRecursive<infer S> ? TRecursive<TRequired<S>> : T extends TIntersect<infer S> ? TIntersect<TRequiredArray<S>> : T extends TUnion<infer S> ? TUnion<TRequiredArray<S>> : T extends TObject<infer S> ? TObject<TRequiredProperties<S>> : T;
365
+ export type TRequired<T extends TSchema> = T extends TRecursive<infer S> ? TRecursive<TRequired<S>> : T extends TIntersect<infer S> ? TIntersect<TRequiredRest<S>> : T extends TUnion<infer S> ? TUnion<TRequiredRest<S>> : T extends TObject<infer S> ? TObject<TRequiredProperties<S>> : T;
356
366
  export type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex' | ({} & string);
357
367
  export type StringContentEncodingOption = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64' | ({} & string);
358
368
  export interface StringOptions extends SchemaOptions {
359
- minLength?: number;
369
+ /** The maximum string length */
360
370
  maxLength?: number;
371
+ /** The minimum string length */
372
+ minLength?: number;
373
+ /** A regular expression pattern this string should match */
361
374
  pattern?: string;
375
+ /** A format this string should match */
362
376
  format?: StringFormatOption;
377
+ /** The content encoding for this string */
363
378
  contentEncoding?: StringContentEncodingOption;
379
+ /** The content media type for this string */
364
380
  contentMediaType?: string;
365
381
  }
366
382
  export interface TString extends TSchema, StringOptions {
@@ -389,14 +405,13 @@ export type TTemplateLiteralConst<T, Acc extends string> = T extends TUnion<infe
389
405
  [K in keyof U]: TTemplateLiteralUnion<Assert<[U[K]], TTemplateLiteralKind[]>, Acc>;
390
406
  }[number] : T extends TTemplateLiteral ? `${Static<T>}` : T extends TLiteral<infer U> ? `${U}` : T extends TString ? `${string}` : T extends TNumber ? `${number}` : T extends TBigInt ? `${bigint}` : T extends TBoolean ? `${boolean}` : never;
391
407
  export type TTemplateLiteralUnion<T extends TTemplateLiteralKind[], Acc extends string = ''> = T extends [infer L, ...infer R] ? `${TTemplateLiteralConst<L, Acc>}${TTemplateLiteralUnion<Assert<R, TTemplateLiteralKind[]>, Acc>}` : Acc;
392
- export type TTemplateLiteralKeyRest<T extends TTemplateLiteral> = Assert<UnionToTuple<Static<T>>, Key[]>;
408
+ export type TTemplateLiteralKeyRest<T extends TTemplateLiteral> = Assert<UnionToTuple<Static<T>>, TPropertyKey[]>;
393
409
  export interface TTemplateLiteral<T extends TTemplateLiteralKind[] = TTemplateLiteralKind[]> extends TSchema {
394
410
  [Kind]: 'TemplateLiteral';
395
411
  static: TTemplateLiteralUnion<T>;
396
412
  type: 'string';
397
413
  pattern: string;
398
414
  }
399
- export type TTupleIntoArray<T extends TTuple<TSchema[]>> = T extends TTuple<infer R> ? AssertRest<R> : never;
400
415
  export type TTupleInfer<T extends TSchema[], P extends unknown[]> = T extends [infer L, ...infer R] ? [Static<AssertType<L>, P>, ...TTupleInfer<AssertRest<R>, P>] : [];
401
416
  export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
402
417
  [Kind]: 'Tuple';
@@ -606,7 +621,7 @@ export declare namespace TypeClone {
606
621
  function Clone<T extends TSchema>(schema: T, options?: SchemaOptions): T;
607
622
  }
608
623
  export declare namespace IndexedAccessor {
609
- function Resolve(schema: TSchema, keys: Key[], options?: SchemaOptions): TSchema;
624
+ function Resolve(schema: TSchema, keys: TPropertyKey[], options?: SchemaOptions): TSchema;
610
625
  }
611
626
  export declare namespace ObjectMap {
612
627
  function Map<T = TSchema>(schema: TSchema, callback: (object: TObject) => TObject, options: SchemaOptions): T;
@@ -684,79 +699,80 @@ export declare class StandardTypeBuilder extends TypeBuilder {
684
699
  /** `[Standard]` Creates an Any type */
685
700
  Any(options?: SchemaOptions): TAny;
686
701
  /** `[Standard]` Creates an Array type */
687
- Array<T extends TSchema>(items: T, options?: ArrayOptions): TArray<T>;
702
+ Array<T extends TSchema>(schema: T, options?: ArrayOptions): TArray<T>;
688
703
  /** `[Standard]` Creates a Boolean type */
689
704
  Boolean(options?: SchemaOptions): TBoolean;
690
- /** `[Standard]` Maps a literal strings first character to uppercase */
705
+ /** `[Standard]` Capitalize a LiteralString type */
691
706
  Capitalize<T extends TLiteral<string>>(schema: T, options?: SchemaOptions): TLiteral<Capitalize<T['const']>>;
692
- /** `[Standard]` Creates a Composite object type. */
707
+ /** `[Standard]` Creates a Composite object type */
693
708
  Composite<T extends TObject[]>(objects: [...T], options?: ObjectOptions): TComposite<T>;
694
709
  /** `[Standard]` Creates a Enum type */
695
710
  Enum<T extends Record<string, string | number>>(item: T, options?: SchemaOptions): TEnum<T>;
696
- /** `[Standard]` A conditional type expression that will return the true type if the left type extends the right */
711
+ /** `[Standard]` Creates a Conditional type */
697
712
  Extends<L extends TSchema, R extends TSchema, T extends TSchema, U extends TSchema>(left: L, right: R, trueType: T, falseType: U, options?: SchemaOptions): TExtends<L, R, T, U>;
698
- /** `[Standard]` Excludes from the left type any type that is not assignable to the right */
699
- Exclude<L extends TSchema, R extends TSchema>(left: L, right: R, options?: SchemaOptions): TExclude<L, R>;
700
- /** `[Standard]` Extracts from the left type any type that is assignable to the right */
701
- Extract<L extends TSchema, R extends TSchema>(left: L, right: R, options?: SchemaOptions): TExtract<L, R>;
702
- /** `[Standard]` Returns indexed property types for the given keys */
713
+ /** `[Standard]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
714
+ Exclude<L extends TSchema, R extends TSchema>(unionType: L, excludedMembers: R, options?: SchemaOptions): TExclude<L, R>;
715
+ /** `[Standard]` Constructs a type by extracting from type all union members that are assignable to union */
716
+ Extract<L extends TSchema, R extends TSchema>(type: L, union: R, options?: SchemaOptions): TExtract<L, R>;
717
+ /** `[Standard]` Returns an Indexed property type for the given keys */
703
718
  Index<T extends TTuple, K extends TNumber>(schema: T, keys: K, options?: SchemaOptions): UnionType<Assert<T['items'], TSchema[]>>;
704
- /** `[Standard]` Returns indexed property types for the given keys */
719
+ /** `[Standard]` Returns an Indexed property type for the given keys */
705
720
  Index<T extends TArray, K extends TNumber>(schema: T, keys: K, options?: SchemaOptions): AssertType<T['items']>;
706
- /** `[Standard]` Returns indexed property types for the given keys */
721
+ /** `[Standard]` Returns an Indexed property type for the given keys */
707
722
  Index<T extends TSchema, K extends TTemplateLiteral>(schema: T, keys: K, options?: SchemaOptions): TIndex<T, TTemplateLiteralKeyRest<K>>;
708
- /** `[Standard]` Returns indexed property types for the given keys */
709
- Index<T extends TSchema, K extends TLiteral<Key>>(schema: T, keys: K, options?: SchemaOptions): TIndex<T, [K['const']]>;
710
- /** `[Standard]` Returns indexed property types for the given keys */
711
- Index<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: [...K], options?: SchemaOptions): TIndex<T, Assert<K, Key[]>>;
712
- /** `[Standard]` Returns indexed property types for the given keys */
713
- Index<T extends TSchema, K extends TUnion<TLiteral<Key>[]>>(schema: T, keys: K, options?: SchemaOptions): TIndex<T, TUnionLiteralKeyRest<K>>;
714
- /** `[Standard]` Returns indexed property types for the given keys */
723
+ /** `[Standard]` Returns an Indexed property type for the given keys */
724
+ Index<T extends TSchema, K extends TLiteral<TPropertyKey>>(schema: T, keys: K, options?: SchemaOptions): TIndex<T, [K['const']]>;
725
+ /** `[Standard]` Returns an Indexed property type for the given keys */
726
+ Index<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: [...K], options?: SchemaOptions): TIndex<T, Assert<K, TPropertyKey[]>>;
727
+ /** `[Standard]` Returns an Indexed property type for the given keys */
728
+ Index<T extends TSchema, K extends TUnion<TLiteral<TPropertyKey>[]>>(schema: T, keys: K, options?: SchemaOptions): TIndex<T, TUnionLiteralKeyRest<K>>;
729
+ /** `[Standard]` Returns an Indexed property type for the given keys */
715
730
  Index<T extends TSchema, K extends TSchema>(schema: T, key: K, options?: SchemaOptions): TSchema;
716
731
  /** `[Standard]` Creates an Integer type */
717
732
  Integer(options?: NumericOptions<number>): TInteger;
718
- /** `[Standard]` Creates a Intersect type */
733
+ /** `[Standard]` Creates an Intersect type */
719
734
  Intersect(allOf: [], options?: SchemaOptions): TNever;
720
- /** `[Standard]` Creates a Intersect type */
735
+ /** `[Standard]` Creates an Intersect type */
721
736
  Intersect<T extends [TSchema]>(allOf: [...T], options?: SchemaOptions): T[0];
737
+ /** `[Standard]` Creates an Intersect type */
722
738
  Intersect<T extends TSchema[]>(allOf: [...T], options?: IntersectOptions): TIntersect<T>;
723
739
  /** `[Standard]` Creates a KeyOf type */
724
740
  KeyOf<T extends TSchema>(schema: T, options?: SchemaOptions): TKeyOf<T>;
725
741
  /** `[Standard]` Creates a Literal type */
726
742
  Literal<T extends TLiteralValue>(value: T, options?: SchemaOptions): TLiteral<T>;
727
- /** `[Standard]` Maps a literal string to lowercase */
743
+ /** `[Standard]` Lowercase a LiteralString type */
728
744
  Lowercase<T extends TLiteral<string>>(schema: T, options?: SchemaOptions): TLiteral<Lowercase<T['const']>>;
729
745
  /** `[Standard]` Creates a Never type */
730
746
  Never(options?: SchemaOptions): TNever;
731
747
  /** `[Standard]` Creates a Not type */
732
- Not<T extends TSchema>(not: T, options?: SchemaOptions): TNot<T>;
748
+ Not<T extends TSchema>(schema: T, options?: SchemaOptions): TNot<T>;
733
749
  /** `[Standard]` Creates a Null type */
734
750
  Null(options?: SchemaOptions): TNull;
735
751
  /** `[Standard]` Creates a Number type */
736
752
  Number(options?: NumericOptions<number>): TNumber;
737
753
  /** `[Standard]` Creates an Object type */
738
754
  Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
739
- /** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
755
+ /** `[Standard]` Constructs a type whose keys are omitted from the given type */
740
756
  Omit<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: readonly [...K], options?: SchemaOptions): TOmit<T, K[number]>;
741
- /** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
757
+ /** `[Standard]` Constructs a type whose keys are omitted from the given type */
742
758
  Omit<T extends TSchema, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: SchemaOptions): TOmit<T, TUnionLiteralKeyRest<K>[number]>;
743
- /** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
759
+ /** `[Standard]` Constructs a type whose keys are omitted from the given type */
744
760
  Omit<T extends TSchema, K extends TLiteral<string>>(schema: T, key: K, options?: SchemaOptions): TOmit<T, K['const']>;
745
- /** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
761
+ /** `[Standard]` Constructs a type whose keys are omitted from the given type */
746
762
  Omit<T extends TSchema, K extends TTemplateLiteral>(schema: T, key: K, options?: SchemaOptions): TOmit<T, TTemplateLiteralKeyRest<K>[number]>;
747
- /** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
763
+ /** `[Standard]` Constructs a type whose keys are omitted from the given type */
748
764
  Omit<T extends TSchema, K extends TNever>(schema: T, key: K, options?: SchemaOptions): TOmit<T, never>;
749
- /** `[Standard]` Creates a mapped type where all properties are Optional */
765
+ /** `[Standard]` Constructs a type where all properties are optional */
750
766
  Partial<T extends TSchema>(schema: T, options?: ObjectOptions): TPartial<T>;
751
- /** `[Standard]` Creates a mapped type whose keys are picked from the given type */
767
+ /** `[Standard]` Constructs a type whose keys are picked from the given type */
752
768
  Pick<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: readonly [...K], options?: SchemaOptions): TPick<T, K[number]>;
753
- /** `[Standard]` Creates a mapped type whose keys are picked from the given type */
769
+ /** `[Standard]` Constructs a type whose keys are picked from the given type */
754
770
  Pick<T extends TSchema, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: SchemaOptions): TPick<T, TUnionLiteralKeyRest<K>[number]>;
755
- /** `[Standard]` Creates a mapped type whose keys are picked from the given type */
771
+ /** `[Standard]` Constructs a type whose keys are picked from the given type */
756
772
  Pick<T extends TSchema, K extends TLiteral<string>>(schema: T, key: K, options?: SchemaOptions): TPick<T, K['const']>;
757
- /** `[Standard]` Creates a mapped type whose keys are picked from the given type */
773
+ /** `[Standard]` Constructs a type whose keys are picked from the given type */
758
774
  Pick<T extends TSchema, K extends TTemplateLiteral>(schema: T, key: K, options?: SchemaOptions): TPick<T, TTemplateLiteralKeyRest<K>[number]>;
759
- /** `[Standard]` Creates a mapped type whose keys are picked from the given type */
775
+ /** `[Standard]` Constructs a type whose keys are picked from the given type */
760
776
  Pick<T extends TSchema, K extends TNever>(schema: T, key: K, options?: SchemaOptions): TPick<T, never>;
761
777
  /** `[Standard]` Creates a Record type */
762
778
  Record<K extends TUnion, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): RecordUnionLiteralType<K, T>;
@@ -774,19 +790,19 @@ export declare class StandardTypeBuilder extends TypeBuilder {
774
790
  Ref<T extends TSchema>(schema: T, options?: SchemaOptions): TRef<T>;
775
791
  /** `[Standard]` Creates a Ref type. */
776
792
  Ref<T extends TSchema>($ref: string, options?: SchemaOptions): TRef<T>;
777
- /** `[Standard]` Creates a mapped type where all properties are Required */
793
+ /** `[Standard]` Constructs a type where all properties are required */
778
794
  Required<T extends TSchema>(schema: T, options?: SchemaOptions): TRequired<T>;
779
- /** `[Standard]` Returns a schema array which allows types to compose with the JavaScript spread operator */
795
+ /** `[Standard]` Extracts the rest array from a Tuple */
780
796
  Rest<T extends TSchema>(schema: T): TRest<T>;
781
797
  /** `[Standard]` Creates a String type */
782
798
  String(options?: StringOptions): TString;
783
- /** `[Standard]` Creates a template literal type from template dsl string */
799
+ /** `[Standard]` Creates a TemplateLiteral type from template dsl string */
784
800
  TemplateLiteral<T extends string>(templateDsl: T, options?: SchemaOptions): TTemplateLiteralDslParser<T>;
785
- /** `[Standard]` Creates a template literal type */
801
+ /** `[Standard]` Creates a TemplateLiteral type */
786
802
  TemplateLiteral<T extends TTemplateLiteralKind[]>(kinds: [...T], options?: SchemaOptions): TTemplateLiteral<T>;
787
803
  /** `[Standard]` Creates a Tuple type */
788
804
  Tuple<T extends TSchema[]>(items: [...T], options?: SchemaOptions): TTuple<T>;
789
- /** `[Standard]` Maps a literal strings first character to lowercase */
805
+ /** `[Standard]` Uncapitalize a LiteralString type */
790
806
  Uncapitalize<T extends TLiteral<string>>(schema: T, options?: SchemaOptions): TLiteral<Uncapitalize<T['const']>>;
791
807
  /** `[Standard]` Creates a Union type */
792
808
  Union(anyOf: [], options?: SchemaOptions): TNever;
@@ -794,19 +810,19 @@ export declare class StandardTypeBuilder extends TypeBuilder {
794
810
  Union<T extends [TSchema]>(anyOf: [...T], options?: SchemaOptions): T[0];
795
811
  /** `[Standard]` Creates a Union type */
796
812
  Union<T extends TSchema[]>(anyOf: [...T], options?: SchemaOptions): TUnion<T>;
797
- /** `[Experimental]` Remaps a TemplateLiteral into a Union representation. This function is known to cause TS compiler crashes for finite templates with large generation counts. Use with caution. */
813
+ /** `[Experimental]` Converts a TemplateLiteral into a Union */
798
814
  Union<T extends TTemplateLiteral>(template: T): TUnionTemplateLiteral<T>;
799
815
  /** `[Standard]` Creates an Unknown type */
800
816
  Unknown(options?: SchemaOptions): TUnknown;
801
- /** `[Standard]` Creates a Unsafe type that infers for the generic argument */
817
+ /** `[Standard]` Creates a Unsafe type that will infers as the generic argument T */
802
818
  Unsafe<T>(options?: UnsafeOptions): TUnsafe<T>;
803
- /** `[Standard]` Maps a literal string to uppercase */
819
+ /** `[Standard]` Uppercase a LiteralString type */
804
820
  Uppercase<T extends TLiteral<string>>(schema: T, options?: SchemaOptions): TLiteral<Uppercase<T['const']>>;
805
821
  }
806
822
  export declare class ExtendedTypeBuilder extends StandardTypeBuilder {
807
823
  /** `[Extended]` Creates a AsyncIterator type */
808
824
  AsyncIterator<T extends TSchema>(items: T, options?: SchemaOptions): TAsyncIterator<T>;
809
- /** `[Extended]` Recursively unwraps Promise from the given type. */
825
+ /** `[Extended]` Constructs a type by recursively unwrapping Promise types */
810
826
  Awaited<T extends TSchema>(schema: T, options?: SchemaOptions): TAwaited<T>;
811
827
  /** `[Extended]` Creates a BigInt type */
812
828
  BigInt(options?: NumericOptions<bigint>): TBigInt;
@@ -818,7 +834,7 @@ export declare class ExtendedTypeBuilder extends StandardTypeBuilder {
818
834
  Date(options?: DateOptions): TDate;
819
835
  /** `[Extended]` Creates a Function type */
820
836
  Function<T extends TSchema[], U extends TSchema>(parameters: [...T], returns: U, options?: SchemaOptions): TFunction<T, U>;
821
- /** `[Extended]` Extracts the InstanceType from the given Constructor */
837
+ /** `[Extended]` Extracts the InstanceType from the given Constructor type */
822
838
  InstanceType<T extends TConstructor<any[], any>>(schema: T, options?: SchemaOptions): TInstanceType<T>;
823
839
  /** `[Extended]` Creates an Iterator type */
824
840
  Iterator<T extends TSchema>(items: T, options?: SchemaOptions): TIterator<T>;
@@ -826,15 +842,15 @@ export declare class ExtendedTypeBuilder extends StandardTypeBuilder {
826
842
  Parameters<T extends TFunction<any[], any>>(schema: T, options?: SchemaOptions): TParameters<T>;
827
843
  /** `[Extended]` Creates a Promise type */
828
844
  Promise<T extends TSchema>(item: T, options?: SchemaOptions): TPromise<T>;
829
- /** `[Extended]` Creates a String pattern type from Regular Expression */
845
+ /** `[Extended]` Creates a String type from a Regular Expression pattern */
830
846
  RegExp(pattern: string, options?: SchemaOptions): TString;
831
- /** `[Extended]` Creates a String pattern type from Regular Expression */
847
+ /** `[Extended]` Creates a String type from a Regular Expression */
832
848
  RegExp(regex: RegExp, options?: SchemaOptions): TString;
833
849
  /**
834
850
  * @deprecated Use `Type.RegExp`
835
851
  */
836
852
  RegEx(regex: RegExp, options?: SchemaOptions): TString;
837
- /** `[Extended]` Extracts the ReturnType from the given Function */
853
+ /** `[Extended]` Extracts the ReturnType from the given Function type */
838
854
  ReturnType<T extends TFunction<any[], any>>(schema: T, options?: SchemaOptions): TReturnType<T>;
839
855
  /** `[Extended]` Creates a Symbol type */
840
856
  Symbol(options?: SchemaOptions): TSymbol;
package/typebox.js CHANGED
@@ -1945,19 +1945,19 @@ class StandardTypeBuilder extends TypeBuilder {
1945
1945
  return this.Create({ ...options, [exports.Kind]: 'Any' });
1946
1946
  }
1947
1947
  /** `[Standard]` Creates an Array type */
1948
- Array(items, options = {}) {
1949
- return this.Create({ ...options, [exports.Kind]: 'Array', type: 'array', items: TypeClone.Clone(items) });
1948
+ Array(schema, options = {}) {
1949
+ return this.Create({ ...options, [exports.Kind]: 'Array', type: 'array', items: TypeClone.Clone(schema) });
1950
1950
  }
1951
1951
  /** `[Standard]` Creates a Boolean type */
1952
1952
  Boolean(options = {}) {
1953
1953
  return this.Create({ ...options, [exports.Kind]: 'Boolean', type: 'boolean' });
1954
1954
  }
1955
- /** `[Standard]` Maps a literal strings first character to uppercase */
1955
+ /** `[Standard]` Capitalize a LiteralString type */
1956
1956
  Capitalize(schema, options = {}) {
1957
1957
  const [first, rest] = [schema.const.slice(0, 1), schema.const.slice(1)];
1958
1958
  return exports.Type.Literal(`${first.toUpperCase()}${rest}`, options);
1959
1959
  }
1960
- /** `[Standard]` Creates a Composite object type. */
1960
+ /** `[Standard]` Creates a Composite object type */
1961
1961
  Composite(objects, options) {
1962
1962
  const intersect = exports.Type.Intersect(objects, {});
1963
1963
  const keys = KeyResolver.ResolveKeys(intersect, { includePatterns: false });
@@ -1971,7 +1971,7 @@ class StandardTypeBuilder extends TypeBuilder {
1971
1971
  const anyOf = values.map((value) => (ValueGuard.IsString(value) ? { [exports.Kind]: 'Literal', type: 'string', const: value } : { [exports.Kind]: 'Literal', type: 'number', const: value }));
1972
1972
  return this.Create({ ...options, [exports.Kind]: 'Union', anyOf });
1973
1973
  }
1974
- /** `[Standard]` A conditional type expression that will return the true type if the left type extends the right */
1974
+ /** `[Standard]` Creates a Conditional type */
1975
1975
  Extends(left, right, trueType, falseType, options = {}) {
1976
1976
  switch (TypeExtends.Extends(left, right)) {
1977
1977
  case TypeExtendsResult.Union:
@@ -1982,35 +1982,35 @@ class StandardTypeBuilder extends TypeBuilder {
1982
1982
  return TypeClone.Clone(falseType, options);
1983
1983
  }
1984
1984
  }
1985
- /** `[Standard]` Excludes from the left type any type that is not assignable to the right */
1986
- Exclude(left, right, options = {}) {
1987
- if (TypeGuard.TTemplateLiteral(left))
1988
- return this.Exclude(TemplateLiteralResolver.Resolve(left), right, options);
1989
- if (TypeGuard.TTemplateLiteral(right))
1990
- return this.Exclude(left, TemplateLiteralResolver.Resolve(right), options);
1991
- if (TypeGuard.TUnion(left)) {
1992
- const narrowed = left.anyOf.filter((inner) => TypeExtends.Extends(inner, right) === TypeExtendsResult.False);
1985
+ /** `[Standard]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
1986
+ Exclude(unionType, excludedMembers, options = {}) {
1987
+ if (TypeGuard.TTemplateLiteral(unionType))
1988
+ return this.Exclude(TemplateLiteralResolver.Resolve(unionType), excludedMembers, options);
1989
+ if (TypeGuard.TTemplateLiteral(excludedMembers))
1990
+ return this.Exclude(unionType, TemplateLiteralResolver.Resolve(excludedMembers), options);
1991
+ if (TypeGuard.TUnion(unionType)) {
1992
+ const narrowed = unionType.anyOf.filter((inner) => TypeExtends.Extends(inner, excludedMembers) === TypeExtendsResult.False);
1993
1993
  return (narrowed.length === 1 ? TypeClone.Clone(narrowed[0], options) : this.Union(narrowed, options));
1994
1994
  }
1995
1995
  else {
1996
- return (TypeExtends.Extends(left, right) !== TypeExtendsResult.False ? this.Never(options) : TypeClone.Clone(left, options));
1996
+ return (TypeExtends.Extends(unionType, excludedMembers) !== TypeExtendsResult.False ? this.Never(options) : TypeClone.Clone(unionType, options));
1997
1997
  }
1998
1998
  }
1999
- /** `[Standard]` Extracts from the left type any type that is assignable to the right */
2000
- Extract(left, right, options = {}) {
2001
- if (TypeGuard.TTemplateLiteral(left))
2002
- return this.Extract(TemplateLiteralResolver.Resolve(left), right, options);
2003
- if (TypeGuard.TTemplateLiteral(right))
2004
- return this.Extract(left, TemplateLiteralResolver.Resolve(right), options);
2005
- if (TypeGuard.TUnion(left)) {
2006
- const narrowed = left.anyOf.filter((inner) => TypeExtends.Extends(inner, right) !== TypeExtendsResult.False);
1999
+ /** `[Standard]` Constructs a type by extracting from type all union members that are assignable to union */
2000
+ Extract(type, union, options = {}) {
2001
+ if (TypeGuard.TTemplateLiteral(type))
2002
+ return this.Extract(TemplateLiteralResolver.Resolve(type), union, options);
2003
+ if (TypeGuard.TTemplateLiteral(union))
2004
+ return this.Extract(type, TemplateLiteralResolver.Resolve(union), options);
2005
+ if (TypeGuard.TUnion(type)) {
2006
+ const narrowed = type.anyOf.filter((inner) => TypeExtends.Extends(inner, union) !== TypeExtendsResult.False);
2007
2007
  return (narrowed.length === 1 ? TypeClone.Clone(narrowed[0], options) : this.Union(narrowed, options));
2008
2008
  }
2009
2009
  else {
2010
- return (TypeExtends.Extends(left, right) !== TypeExtendsResult.False ? TypeClone.Clone(left, options) : this.Never(options));
2010
+ return (TypeExtends.Extends(type, union) !== TypeExtendsResult.False ? TypeClone.Clone(type, options) : this.Never(options));
2011
2011
  }
2012
2012
  }
2013
- /** `[Standard]` Returns indexed property types for the given keys */
2013
+ /** `[Standard]` Returns an Indexed property type for the given keys */
2014
2014
  Index(schema, unresolved, options = {}) {
2015
2015
  if (TypeGuard.TArray(schema) && TypeGuard.TNumber(unresolved)) {
2016
2016
  return TypeClone.Clone(schema.items, options);
@@ -2030,6 +2030,7 @@ class StandardTypeBuilder extends TypeBuilder {
2030
2030
  Integer(options = {}) {
2031
2031
  return this.Create({ ...options, [exports.Kind]: 'Integer', type: 'integer' });
2032
2032
  }
2033
+ /** `[Standard]` Creates an Intersect type */
2033
2034
  Intersect(allOf, options = {}) {
2034
2035
  if (allOf.length === 0)
2035
2036
  return exports.Type.Never();
@@ -2075,7 +2076,7 @@ class StandardTypeBuilder extends TypeBuilder {
2075
2076
  Literal(value, options = {}) {
2076
2077
  return this.Create({ ...options, [exports.Kind]: 'Literal', const: value, type: typeof value });
2077
2078
  }
2078
- /** `[Standard]` Maps a literal string to lowercase */
2079
+ /** `[Standard]` Lowercase a LiteralString type */
2079
2080
  Lowercase(schema, options = {}) {
2080
2081
  return exports.Type.Literal(schema.const.toLowerCase(), options);
2081
2082
  }
@@ -2084,8 +2085,8 @@ class StandardTypeBuilder extends TypeBuilder {
2084
2085
  return this.Create({ ...options, [exports.Kind]: 'Never', not: {} });
2085
2086
  }
2086
2087
  /** `[Standard]` Creates a Not type */
2087
- Not(not, options) {
2088
- return this.Create({ ...options, [exports.Kind]: 'Not', not });
2088
+ Not(schema, options) {
2089
+ return this.Create({ ...options, [exports.Kind]: 'Not', not: TypeClone.Clone(schema) });
2089
2090
  }
2090
2091
  /** `[Standard]` Creates a Null type */
2091
2092
  Null(options = {}) {
@@ -2109,6 +2110,7 @@ class StandardTypeBuilder extends TypeBuilder {
2109
2110
  return this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: 'Object', type: 'object', properties: clonedProperties });
2110
2111
  }
2111
2112
  }
2113
+ /** `[Standard]` Constructs a type whose keys are omitted from the given type */
2112
2114
  Omit(schema, unresolved, options = {}) {
2113
2115
  const keys = KeyArrayResolver.Resolve(unresolved);
2114
2116
  // prettier-ignore
@@ -2125,7 +2127,7 @@ class StandardTypeBuilder extends TypeBuilder {
2125
2127
  return this.Create(object);
2126
2128
  }, options);
2127
2129
  }
2128
- /** `[Standard]` Creates a mapped type where all properties are Optional */
2130
+ /** `[Standard]` Constructs a type where all properties are optional */
2129
2131
  Partial(schema, options = {}) {
2130
2132
  // prettier-ignore
2131
2133
  return ObjectMap.Map(schema, (object) => {
@@ -2135,6 +2137,7 @@ class StandardTypeBuilder extends TypeBuilder {
2135
2137
  return this.Object(properties, this.Discard(object, 'required') /* object used as options to retain other constraints */);
2136
2138
  }, options);
2137
2139
  }
2140
+ /** `[Standard]` Constructs a type whose keys are picked from the given type */
2138
2141
  Pick(schema, unresolved, options = {}) {
2139
2142
  const keys = KeyArrayResolver.Resolve(unresolved);
2140
2143
  // prettier-ignore
@@ -2203,7 +2206,7 @@ class StandardTypeBuilder extends TypeBuilder {
2203
2206
  throw Error('StandardTypeBuilder.Ref: Target type must specify an $id');
2204
2207
  return this.Create({ ...options, [exports.Kind]: 'Ref', $ref: unresolved.$id });
2205
2208
  }
2206
- /** `[Standard]` Creates a mapped type where all properties are Required */
2209
+ /** `[Standard]` Constructs a type where all properties are required */
2207
2210
  Required(schema, options = {}) {
2208
2211
  // prettier-ignore
2209
2212
  return ObjectMap.Map(schema, (object) => {
@@ -2213,7 +2216,7 @@ class StandardTypeBuilder extends TypeBuilder {
2213
2216
  return this.Object(properties, object /* object used as options to retain other constraints */);
2214
2217
  }, options);
2215
2218
  }
2216
- /** `[Standard]` Returns a schema array which allows types to compose with the JavaScript spread operator */
2219
+ /** `[Standard]` Extracts the rest array from a Tuple */
2217
2220
  Rest(schema) {
2218
2221
  if (TypeGuard.TTuple(schema)) {
2219
2222
  if (ValueGuard.IsUndefined(schema.items))
@@ -2228,7 +2231,7 @@ class StandardTypeBuilder extends TypeBuilder {
2228
2231
  String(options = {}) {
2229
2232
  return this.Create({ ...options, [exports.Kind]: 'String', type: 'string' });
2230
2233
  }
2231
- /** `[Standard]` Creates a template literal type */
2234
+ /** `[Standard]` Creates a TemplateLiteral type */
2232
2235
  TemplateLiteral(unresolved, options = {}) {
2233
2236
  // prettier-ignore
2234
2237
  const pattern = (ValueGuard.IsString(unresolved))
@@ -2246,11 +2249,12 @@ class StandardTypeBuilder extends TypeBuilder {
2246
2249
  { ...options, [exports.Kind]: 'Tuple', type: 'array', minItems, maxItems });
2247
2250
  return this.Create(schema);
2248
2251
  }
2249
- /** `[Standard]` Maps a literal strings first character to lowercase */
2252
+ /** `[Standard]` Uncapitalize a LiteralString type */
2250
2253
  Uncapitalize(schema, options = {}) {
2251
2254
  const [first, rest] = [schema.const.slice(0, 1), schema.const.slice(1)];
2252
2255
  return exports.Type.Literal(`${first.toLocaleLowerCase()}${rest}`, options);
2253
2256
  }
2257
+ /** `[Standard]` Creates a Union type */
2254
2258
  Union(union, options = {}) {
2255
2259
  if (TypeGuard.TTemplateLiteral(union)) {
2256
2260
  return TemplateLiteralResolver.Resolve(union);
@@ -2269,11 +2273,11 @@ class StandardTypeBuilder extends TypeBuilder {
2269
2273
  Unknown(options = {}) {
2270
2274
  return this.Create({ ...options, [exports.Kind]: 'Unknown' });
2271
2275
  }
2272
- /** `[Standard]` Creates a Unsafe type that infers for the generic argument */
2276
+ /** `[Standard]` Creates a Unsafe type that will infers as the generic argument T */
2273
2277
  Unsafe(options = {}) {
2274
2278
  return this.Create({ ...options, [exports.Kind]: options[exports.Kind] || 'Unsafe' });
2275
2279
  }
2276
- /** `[Standard]` Maps a literal string to uppercase */
2280
+ /** `[Standard]` Uppercase a LiteralString type */
2277
2281
  Uppercase(schema, options = {}) {
2278
2282
  return exports.Type.Literal(schema.const.toUpperCase(), options);
2279
2283
  }
@@ -2287,7 +2291,7 @@ class ExtendedTypeBuilder extends StandardTypeBuilder {
2287
2291
  AsyncIterator(items, options = {}) {
2288
2292
  return this.Create({ ...options, [exports.Kind]: 'AsyncIterator', type: 'AsyncIterator', items: TypeClone.Clone(items) });
2289
2293
  }
2290
- /** `[Extended]` Recursively unwraps Promise from the given type. */
2294
+ /** `[Extended]` Constructs a type by recursively unwrapping Promise types */
2291
2295
  Awaited(schema, options = {}) {
2292
2296
  const AwaitedRest = (rest) => {
2293
2297
  if (rest.length === 0)
@@ -2325,7 +2329,7 @@ class ExtendedTypeBuilder extends StandardTypeBuilder {
2325
2329
  const clonedParameters = parameters.map((parameter) => TypeClone.Clone(parameter));
2326
2330
  return this.Create({ ...options, [exports.Kind]: 'Function', type: 'function', parameters: clonedParameters, returns: clonedReturns });
2327
2331
  }
2328
- /** `[Extended]` Extracts the InstanceType from the given Constructor */
2332
+ /** `[Extended]` Extracts the InstanceType from the given Constructor type */
2329
2333
  InstanceType(schema, options = {}) {
2330
2334
  return TypeClone.Clone(schema.returns, options);
2331
2335
  }
@@ -2341,7 +2345,7 @@ class ExtendedTypeBuilder extends StandardTypeBuilder {
2341
2345
  Promise(item, options = {}) {
2342
2346
  return this.Create({ ...options, [exports.Kind]: 'Promise', type: 'Promise', item: TypeClone.Clone(item) });
2343
2347
  }
2344
- /** `[Extended]` Creates a String pattern type from Regular Expression */
2348
+ /** `[Extended]` Creates a String type */
2345
2349
  RegExp(unresolved, options = {}) {
2346
2350
  const pattern = ValueGuard.IsString(unresolved) ? unresolved : unresolved.source;
2347
2351
  return this.Create({ ...options, [exports.Kind]: 'String', type: 'string', pattern });
@@ -2352,7 +2356,7 @@ class ExtendedTypeBuilder extends StandardTypeBuilder {
2352
2356
  RegEx(regex, options = {}) {
2353
2357
  return this.RegExp(regex, options);
2354
2358
  }
2355
- /** `[Extended]` Extracts the ReturnType from the given Function */
2359
+ /** `[Extended]` Extracts the ReturnType from the given Function type */
2356
2360
  ReturnType(schema, options = {}) {
2357
2361
  return TypeClone.Clone(schema.returns, options);
2358
2362
  }