@sinclair/typebox 0.27.8 → 0.28.0

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/typebox.d.ts CHANGED
@@ -19,6 +19,16 @@ export type Evaluate<T> = T extends infer O ? {
19
19
  [K in keyof O]: O[K];
20
20
  } : never;
21
21
  export type Ensure<T> = T extends infer U ? U : never;
22
+ export type AssertProperties<T> = T extends TProperties ? T : TProperties;
23
+ export type AssertSchemas<T, E extends TSchema[] = TSchema[]> = T extends E ? T : [];
24
+ export type AssertSchema<T, E extends TSchema = TSchema> = T extends E ? T : TNever;
25
+ export type AssertObjects<T> = Assert<T, TObject[]>;
26
+ export type AssertObject<T> = Assert<T, TObject>;
27
+ export type AssertKeys<T> = Assert<T, Key[]>;
28
+ export type AssertKey<T> = Assert<T, Key>;
29
+ export type Key = keyof any;
30
+ export type IntersectType<T extends TSchema[]> = T extends [] ? TNever : T extends [TSchema] ? AssertSchema<T[0]> : TIntersect<T>;
31
+ export type UnionType<T extends TSchema[]> = T extends [] ? TNever : T extends [TSchema] ? AssertSchema<T[0]> : TUnion<T>;
22
32
  export type TModifier = TReadonlyOptional<TSchema> | TOptional<TSchema> | TReadonly<TSchema>;
23
33
  export type TReadonly<T extends TSchema> = T & {
24
34
  [Modifier]: 'Readonly';
@@ -53,7 +63,6 @@ export interface TSchema extends SchemaOptions, TKind {
53
63
  static: unknown;
54
64
  }
55
65
  export type TAnySchema = TSchema | TAny | TArray | TBigInt | TBoolean | TConstructor | TDate | TEnum | TFunction | TInteger | TIntersect | TLiteral | TNot | TNull | TNumber | TObject | TPromise | TRecord | TRef | TString | TSymbol | TTemplateLiteral | TThis | TTuple | TUndefined | TUnion | TUint8Array | TUnknown | TVoid;
56
- export type TNumeric = TInteger | TNumber;
57
66
  export interface NumericOptions<N extends number | bigint> extends SchemaOptions {
58
67
  exclusiveMaximum?: N;
59
68
  exclusiveMinimum?: N;
@@ -89,20 +98,22 @@ export interface TBoolean extends TSchema {
89
98
  }
90
99
  export type TConstructorParameters<T extends TConstructor<TSchema[], TSchema>> = TTuple<T['parameters']>;
91
100
  export type TInstanceType<T extends TConstructor<TSchema[], TSchema>> = T['returns'];
92
- export type TCompositeEvaluateArray<T extends readonly TSchema[], P extends unknown[]> = {
93
- [K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
94
- };
95
- export type TCompositeArray<T extends readonly TObject[]> = {
96
- [K in keyof T]: T[K] extends TObject<infer P> ? P : {};
97
- };
98
- export type TCompositeProperties<I extends unknown, T extends readonly any[]> = Evaluate<T extends [infer A, ...infer B] ? TCompositeProperties<I & A, B> : I extends object ? I : {}>;
99
- export interface TComposite<T extends TObject[] = TObject[]> extends TObject {
100
- [Hint]: 'Composite';
101
- static: Evaluate<TCompositeProperties<unknown, TCompositeEvaluateArray<T, this['params']>>>;
102
- properties: TCompositeProperties<unknown, TCompositeArray<T>>;
103
- }
101
+ export type TCompositeIsOptional<T extends TSchema> = T extends TOptional<T> | TReadonlyOptional<T> ? true : false;
102
+ export type TCompositeOptional<T extends TSchema[]> = T extends [infer L, ...infer R] ? TCompositeIsOptional<AssertSchema<L>> extends false ? false : TCompositeOptional<AssertSchemas<R>> : true;
103
+ export type TCompositeKeyOfUnion1<T extends TObject> = keyof T['properties'];
104
+ export type TCompositeKeyOfUnion2<T extends TObject[]> = T extends [infer L, ...infer R] ? TCompositeKeyOfUnion1<Assert<L, TObject>> | TCompositeKeyOfUnion2<Assert<R, TObject[]>> : never;
105
+ export type TCompositeKeyOf<T extends TObject[]> = UnionToTuple<TCompositeKeyOfUnion2<T>>;
106
+ export type TCompositePropertiesWithKey1<T extends TObject, K extends Key> = K extends keyof T['properties'] ? [T['properties'][K]] : [];
107
+ export type TCompositePropertiesWithKey2<T extends TObject[], K extends Key> = T extends [infer L, ...infer R] ? [...TCompositePropertiesWithKey1<AssertObject<L>, K>, ...TCompositePropertiesWithKey2<AssertObjects<R>, K>] : [];
108
+ export type TCompositeObjectProperty<T extends TObject[], K extends Key> = TCompositePropertiesWithKey2<T, K> extends infer S ? TCompositeOptional<AssertSchemas<S>> extends true ? {
109
+ [_ in K]: TOptional<IntersectType<AssertSchemas<S>>>;
110
+ } : {
111
+ [_ in K]: IntersectType<AssertSchemas<S>>;
112
+ } : {};
113
+ export type TCompositeObjectsWithKeys<T extends TObject[], K extends Key[]> = K extends [infer L, ...infer R] ? L extends Key ? TCompositeObjectProperty<T, L> & TCompositeObjectsWithKeys<T, AssertKeys<R>> : {} : {};
114
+ export type TComposite<T extends TObject[]> = Ensure<TObject<Evaluate<TCompositeObjectsWithKeys<T, AssertKeys<TCompositeKeyOf<T>>>>>>;
104
115
  export type TConstructorParameterArray<T extends readonly TSchema[], P extends unknown[]> = [...{
105
- [K in keyof T]: Static<Assert<T[K], TSchema>, P>;
116
+ [K in keyof T]: Static<AssertSchema<T[K]>, P>;
106
117
  }];
107
118
  export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
108
119
  [Kind]: 'Constructor';
@@ -133,25 +144,25 @@ export interface TEnum<T extends Record<string, string | number> = Record<string
133
144
  static: T[keyof T];
134
145
  anyOf: TLiteral<string | number>[];
135
146
  }
136
- export type TExtends<L extends TSchema, R extends TSchema, T extends TSchema, U extends TSchema> = (Static<L> extends Static<R> ? T : U) extends infer O ? UnionToTuple<O> extends [infer X, infer Y] ? TUnion<[Assert<X, TSchema>, Assert<Y, TSchema>]> : Assert<O, TSchema> : never;
137
- export type TExcludeTemplateLiteralResult<T extends string> = TUnionResult<Assert<UnionToTuple<{
147
+ export type TExtends<L extends TSchema, R extends TSchema, T extends TSchema, U extends TSchema> = (Static<L> extends Static<R> ? T : U) extends infer O ? UnionToTuple<O> extends [infer X, infer Y] ? TUnion<[AssertSchema<X>, AssertSchema<Y>]> : AssertSchema<O> : never;
148
+ export type TExcludeTemplateLiteralResult<T extends string> = UnionType<AssertSchemas<UnionToTuple<{
138
149
  [K in T]: TLiteral<K>;
139
- }[T]>, TSchema[]>>;
150
+ }[T]>>>;
140
151
  export type TExcludeTemplateLiteral<T extends TTemplateLiteral, U extends TSchema> = Exclude<Static<T>, Static<U>> extends infer S ? TExcludeTemplateLiteralResult<Assert<S, string>> : never;
141
- export type TExcludeArray<T extends TSchema[], U extends TSchema> = Assert<UnionToTuple<{
142
- [K in keyof T]: Static<Assert<T[K], TSchema>> extends Static<U> ? never : T[K];
143
- }[number]>, TSchema[]> extends infer R ? TUnionResult<Assert<R, TSchema[]>> : never;
152
+ export type TExcludeArray<T extends TSchema[], U extends TSchema> = AssertSchemas<UnionToTuple<{
153
+ [K in keyof T]: Static<AssertSchema<T[K]>> extends Static<U> ? never : T[K];
154
+ }[number]>> extends infer R ? UnionType<AssertSchemas<R>> : never;
144
155
  export type TExclude<T extends TSchema, U extends TSchema> = T extends TTemplateLiteral ? TExcludeTemplateLiteral<T, U> : T extends TUnion<infer S> ? TExcludeArray<S, U> : T extends U ? TNever : T;
145
- export type TExtractTemplateLiteralResult<T extends string> = TUnionResult<Assert<UnionToTuple<{
156
+ export type TExtractTemplateLiteralResult<T extends string> = UnionType<AssertSchemas<UnionToTuple<{
146
157
  [K in T]: TLiteral<K>;
147
- }[T]>, TSchema[]>>;
158
+ }[T]>>>;
148
159
  export type TExtractTemplateLiteral<T extends TTemplateLiteral, U extends TSchema> = Extract<Static<T>, Static<U>> extends infer S ? TExtractTemplateLiteralResult<Assert<S, string>> : never;
149
- export type TExtractArray<T extends TSchema[], U extends TSchema> = Assert<UnionToTuple<{
150
- [K in keyof T]: Static<Assert<T[K], TSchema>> extends Static<U> ? T[K] : never;
151
- }[number]>, TSchema[]> extends infer R ? TUnionResult<Assert<R, TSchema[]>> : never;
160
+ export type TExtractArray<T extends TSchema[], U extends TSchema> = AssertSchemas<UnionToTuple<{
161
+ [K in keyof T]: Static<AssertSchema<T[K]>> extends Static<U> ? T[K] : never;
162
+ }[number]>> extends infer R ? UnionType<AssertSchemas<R>> : never;
152
163
  export type TExtract<T extends TSchema, U extends TSchema> = T extends TTemplateLiteral ? TExtractTemplateLiteral<T, U> : T extends TUnion<infer S> ? TExtractArray<S, U> : T extends U ? T : T;
153
164
  export type TFunctionParameters<T extends readonly TSchema[], P extends unknown[]> = [...{
154
- [K in keyof T]: Static<Assert<T[K], TSchema>, P>;
165
+ [K in keyof T]: Static<AssertSchema<T[K]>, P>;
155
166
  }];
156
167
  export interface TFunction<T extends readonly TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
157
168
  [Kind]: 'Function';
@@ -161,6 +172,18 @@ export interface TFunction<T extends readonly TSchema[] = TSchema[], U extends T
161
172
  parameters: T;
162
173
  returns: U;
163
174
  }
175
+ export type IndexKey = keyof any;
176
+ export type TIndexProperty<T extends TProperties, K extends IndexKey> = K extends keyof T ? [T[K]] : [
177
+ ];
178
+ export type TIndexTuple<T extends TSchema[], K extends IndexKey> = K extends keyof T ? [T[K]] : [
179
+ ];
180
+ export type TIndexComposite<T extends TSchema[], K extends IndexKey> = T extends [infer L, ...infer R] ? [...TIndexKey<AssertSchema<L>, K>, ...TIndexComposite<AssertSchemas<R>, K>] : [
181
+ ];
182
+ export type TIndexKey<T extends TSchema, K extends IndexKey> = T extends TRecursive<infer S> ? TIndexKey<S, K> : T extends TIntersect<infer S> ? TIndexComposite<S, K> : T extends TUnion<infer S> ? TIndexComposite<S, K> : T extends TObject<infer S> ? TIndexProperty<S, K> : T extends TTuple<infer S> ? TIndexTuple<S, K> : T extends TArray<infer S> ? S : [
183
+ ];
184
+ export type TIndexKeys<T extends TSchema, K extends IndexKey[]> = K extends [infer L, ...infer R] ? [...TIndexKey<T, Assert<L, IndexKey>>, ...TIndexKeys<T, Assert<R, IndexKey[]>>] : [
185
+ ];
186
+ export type TIndex<T extends TSchema, K extends IndexKey[]> = TIndexKeys<T, K> extends infer R ? T extends TRecursive<infer S> ? TIndex<S, K> : T extends TTuple ? UnionType<AssertSchemas<R>> : T extends TIntersect ? UnionType<AssertSchemas<R>> : T extends TUnion ? UnionType<AssertSchemas<R>> : T extends TObject ? UnionType<AssertSchemas<R>> : T extends TArray ? UnionType<AssertSchemas<R>> : TNever : TNever;
164
187
  export interface TInteger extends TSchema, NumericOptions<number> {
165
188
  [Kind]: 'Integer';
166
189
  static: number;
@@ -173,18 +196,20 @@ export interface IntersectOptions extends SchemaOptions {
173
196
  export interface TIntersect<T extends TSchema[] = TSchema[]> extends TSchema, IntersectOptions {
174
197
  [Kind]: 'Intersect';
175
198
  static: TupleToIntersect<{
176
- [K in keyof T]: Static<Assert<T[K], TSchema>, this['params']>;
199
+ [K in keyof T]: Static<AssertSchema<T[K]>, this['params']>;
177
200
  }>;
178
201
  type?: 'object';
179
202
  allOf: [...T];
180
203
  }
181
- export type TKeyOfTuple<T extends TSchema> = {
182
- [K in keyof Static<T>]: TLiteral<Assert<K, TLiteralValue>>;
183
- } extends infer U ? UnionToTuple<Exclude<{
184
- [K in keyof U]: U[K];
185
- }[keyof U], undefined>> : never;
186
- export type TKeyOf<T extends TSchema = TSchema> = (T extends TRecursive<infer S> ? TKeyOfTuple<S> : 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] : [
187
- ]) extends infer R ? TUnionResult<Assert<R, TSchema[]>> : never;
204
+ export type TKeyOfProperties<T extends TSchema> = Static<T> extends infer S ? UnionToTuple<{
205
+ [K in keyof S]: TLiteral<`${Assert<K, TLiteralValue>}`>;
206
+ }[keyof S]> : [];
207
+ export type TKeyOfIndicesArray<T extends TSchema[]> = UnionToTuple<keyof T & `${number}`>;
208
+ export type TKeyOfIndices<T extends TSchema[]> = AssertSchemas<TKeyOfIndicesArray<T> extends infer R ? {
209
+ [K in keyof R]: TLiteral<Assert<R[K], TLiteralValue>>;
210
+ } : []>;
211
+ export type TKeyOf<T extends TSchema = TSchema> = (T extends TRecursive<infer S> ? TKeyOfProperties<S> : T extends TIntersect ? TKeyOfProperties<T> : T extends TUnion ? TKeyOfProperties<T> : T extends TObject ? TKeyOfProperties<T> : T extends TTuple<infer K> ? TKeyOfIndices<K> : T extends TArray ? [TNumber] : T extends TRecord<infer K> ? [K] : [
212
+ ]) extends infer R ? UnionType<AssertSchemas<R>> : never;
188
213
  export type TLiteralValue = string | number | boolean;
189
214
  export interface TLiteral<T extends TLiteralValue = TLiteralValue> extends TSchema {
190
215
  [Kind]: 'Literal';
@@ -244,29 +269,29 @@ export interface TObject<T extends TProperties = TProperties> extends TSchema, O
244
269
  properties: T;
245
270
  required?: string[];
246
271
  }
247
- export type TOmitArray<T extends TSchema[], K extends keyof any> = Assert<{
248
- [K2 in keyof T]: TOmit<Assert<T[K2], TSchema>, K>;
249
- }, TSchema[]>;
250
- export type TOmitProperties<T extends TProperties, K extends keyof any> = Evaluate<Assert<Omit<T, K>, TProperties>>;
251
- export type TOmit<T extends TSchema = TSchema, K extends keyof any = keyof any> = T extends TRecursive<infer S> ? TRecursive<TOmit<S, K>> : 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
- export type TParameters<T extends TFunction> = TTuple<T['parameters']>;
253
- export type TPartialObjectArray<T extends TObject[]> = Assert<{
254
- [K in keyof T]: TPartial<Assert<T[K], TObject>>;
272
+ export type TOmitArray<T extends TSchema[], K extends keyof any> = AssertSchemas<{
273
+ [K2 in keyof T]: TOmit<AssertSchema<T[K2]>, K>;
274
+ }>;
275
+ export type TOmitProperties<T extends TProperties, K extends keyof any> = Evaluate<AssertProperties<Omit<T, K>>>;
276
+ export type TOmit<T extends TSchema = TSchema, K extends keyof any = keyof any> = T extends TRecursive<infer S> ? TRecursive<TOmit<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;
277
+ export type TParameters<T extends TFunction> = Ensure<TTuple<T['parameters']>>;
278
+ export type TPartialObjectArray<T extends TObject[]> = AssertSchemas<{
279
+ [K in keyof T]: TPartial<AssertSchema<T[K], TObject>>;
255
280
  }, TObject[]>;
256
- export type TPartialArray<T extends TSchema[]> = Assert<{
257
- [K in keyof T]: TPartial<Assert<T[K], TSchema>>;
258
- }, TSchema[]>;
259
- export type TPartialProperties<T extends TProperties> = Evaluate<Assert<{
281
+ export type TPartialArray<T extends TSchema[]> = AssertSchemas<{
282
+ [K in keyof T]: TPartial<AssertSchema<T[K]>>;
283
+ }>;
284
+ export type TPartialProperties<T extends TProperties> = Evaluate<AssertProperties<{
260
285
  [K in keyof T]: T[K] extends TReadonlyOptional<infer U> ? TReadonlyOptional<U> : T[K] extends TReadonly<infer U> ? TReadonlyOptional<U> : T[K] extends TOptional<infer U> ? TOptional<U> : TOptional<T[K]>;
261
- }, TProperties>>;
262
- export type TPartial<T extends TSchema> = T extends TRecursive<infer S> ? TRecursive<TPartial<S>> : T extends TComposite<infer S> ? TComposite<TPartialArray<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;
286
+ }>>;
287
+ 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;
263
288
  export type TPickArray<T extends TSchema[], K extends keyof any> = {
264
- [K2 in keyof T]: TPick<Assert<T[K2], TSchema>, K>;
289
+ [K2 in keyof T]: TPick<AssertSchema<T[K2]>, K>;
265
290
  };
266
291
  export type TPickProperties<T extends TProperties, K extends keyof any> = Pick<T, Assert<Extract<K, keyof T>, keyof T>> extends infer R ? ({
267
- [K in keyof R]: Assert<R[K], TSchema> extends TSchema ? R[K] : never;
292
+ [K in keyof R]: AssertSchema<R[K]> extends TSchema ? R[K] : never;
268
293
  }) : never;
269
- export type TPick<T extends TSchema = TSchema, K extends keyof any = keyof any> = T extends TRecursive<infer S> ? TRecursive<TPick<S, K>> : 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;
294
+ export type TPick<T extends TSchema = TSchema, K extends keyof any = keyof any> = T extends TRecursive<infer S> ? TRecursive<TPick<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
295
  export interface TPromise<T extends TSchema = TSchema> extends TSchema {
271
296
  [Kind]: 'Promise';
272
297
  static: Promise<Static<T, this['params']>>;
@@ -294,7 +319,7 @@ export interface TRecord<K extends RecordKey = RecordKey, T extends TSchema = TS
294
319
  patternProperties: {
295
320
  [pattern: string]: T;
296
321
  };
297
- additionalProperties: false;
322
+ additionalProperties: TAdditionalProperties;
298
323
  }
299
324
  export interface TThis extends TSchema {
300
325
  [Kind]: 'This';
@@ -312,23 +337,23 @@ export interface TRef<T extends TSchema = TSchema> extends TSchema {
312
337
  $ref: string;
313
338
  }
314
339
  export type TReturnType<T extends TFunction> = T['returns'];
315
- export type TRequiredArray<T extends TSchema[]> = Assert<{
316
- [K in keyof T]: TRequired<Assert<T[K], TSchema>>;
317
- }, TSchema[]>;
318
- export type TRequiredProperties<T extends TProperties> = Evaluate<Assert<{
340
+ export type TRequiredArray<T extends TSchema[]> = AssertSchemas<{
341
+ [K in keyof T]: TRequired<AssertSchema<T[K]>>;
342
+ }>;
343
+ export type TRequiredProperties<T extends TProperties> = Evaluate<AssertProperties<{
319
344
  [K in keyof T]: T[K] extends TReadonlyOptional<infer U> ? TReadonly<U> : T[K] extends TReadonly<infer U> ? TReadonly<U> : T[K] extends TOptional<infer U> ? U : T[K];
320
- }, TProperties>>;
321
- export type TRequired<T extends TSchema> = T extends TRecursive<infer S> ? TRecursive<TRequired<S>> : T extends TComposite<infer S> ? TComposite<TRequiredArray<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;
345
+ }>>;
346
+ 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;
322
347
  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';
323
- export interface StringOptions<Format extends string> extends SchemaOptions {
348
+ export interface StringOptions extends SchemaOptions {
324
349
  minLength?: number;
325
350
  maxLength?: number;
326
351
  pattern?: string;
327
- format?: Format;
352
+ format?: string;
328
353
  contentEncoding?: '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64';
329
354
  contentMediaType?: string;
330
355
  }
331
- export interface TString<Format extends string = string> extends TSchema, StringOptions<Format> {
356
+ export interface TString extends TSchema, StringOptions {
332
357
  [Kind]: 'String';
333
358
  static: string;
334
359
  type: 'string';
@@ -341,20 +366,21 @@ export interface TSymbol extends TSchema, SchemaOptions {
341
366
  typeOf: 'Symbol';
342
367
  }
343
368
  export type IsTemplateLiteralFiniteCheck<T> = T extends TTemplateLiteral<infer U> ? IsTemplateLiteralFiniteArray<Assert<U, TTemplateLiteralKind[]>> : T extends TUnion<infer U> ? IsTemplateLiteralFiniteArray<Assert<U, TTemplateLiteralKind[]>> : T extends TString ? false : T extends TBoolean ? false : T extends TNumber ? false : T extends TInteger ? false : T extends TBigInt ? false : T extends TLiteral ? true : false;
344
- export type IsTemplateLiteralFiniteArray<T extends TTemplateLiteralKind[]> = T extends [infer L, ...infer R] ? IsTemplateLiteralFiniteCheck<L> extends false ? false : IsTemplateLiteralFiniteArray<Assert<R, TTemplateLiteralKind[]>> : T extends [infer L] ? IsTemplateLiteralFiniteCheck<L> extends false ? false : true : true;
369
+ export type IsTemplateLiteralFiniteArray<T extends TTemplateLiteralKind[]> = T extends [infer L, ...infer R] ? IsTemplateLiteralFiniteCheck<L> extends false ? false : IsTemplateLiteralFiniteArray<Assert<R, TTemplateLiteralKind[]>> : true;
345
370
  export type IsTemplateLiteralFinite<T> = T extends TTemplateLiteral<infer U> ? IsTemplateLiteralFiniteArray<U> : false;
346
371
  export type TTemplateLiteralKind = TUnion | TLiteral | TInteger | TTemplateLiteral | TNumber | TBigInt | TString | TBoolean | TNever;
347
372
  export type TTemplateLiteralConst<T, Acc extends string> = T extends TUnion<infer U> ? {
348
373
  [K in keyof U]: TTemplateLiteralUnion<Assert<[U[K]], TTemplateLiteralKind[]>, Acc>;
349
374
  }[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;
350
- export type TTemplateLiteralUnion<T extends TTemplateLiteralKind[], Acc extends string = ''> = T extends [infer L, ...infer R] ? `${TTemplateLiteralConst<L, Acc>}${TTemplateLiteralUnion<Assert<R, TTemplateLiteralKind[]>, Acc>}` : T extends [infer L] ? `${TTemplateLiteralConst<L, Acc>}${Acc}` : Acc;
375
+ export type TTemplateLiteralUnion<T extends TTemplateLiteralKind[], Acc extends string = ''> = T extends [infer L, ...infer R] ? `${TTemplateLiteralConst<L, Acc>}${TTemplateLiteralUnion<Assert<R, TTemplateLiteralKind[]>, Acc>}` : Acc;
376
+ export type TTemplateLiteralKeyArray<T extends TTemplateLiteral> = AssertKeys<UnionToTuple<Static<T>>>;
351
377
  export interface TTemplateLiteral<T extends TTemplateLiteralKind[] = TTemplateLiteralKind[]> extends TSchema {
352
378
  [Kind]: 'TemplateLiteral';
353
379
  static: TTemplateLiteralUnion<T>;
354
380
  type: 'string';
355
381
  pattern: string;
356
382
  }
357
- export type TTupleIntoArray<T extends TTuple<TSchema[]>> = T extends TTuple<infer R> ? Assert<R, TSchema[]> : never;
383
+ export type TTupleIntoArray<T extends TTuple<TSchema[]>> = T extends TTuple<infer R> ? AssertSchemas<R> : never;
358
384
  export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
359
385
  [Kind]: 'Tuple';
360
386
  static: {
@@ -372,12 +398,10 @@ export interface TUndefined extends TSchema {
372
398
  type: 'null';
373
399
  typeOf: 'Undefined';
374
400
  }
375
- export type TUnionOfLiteralArray<T extends TLiteral<string>[]> = {
376
- [K in keyof T]: Assert<T[K], TLiteral>['const'];
377
- }[number];
378
- export type TUnionOfLiteral<T extends TUnion<TLiteral<string>[]>> = TUnionOfLiteralArray<T['anyOf']>;
379
- export type TUnionResult<T extends TSchema[]> = T extends [] ? TNever : T extends [infer S] ? S : TUnion<T>;
380
- export type TUnionTemplateLiteral<T extends TTemplateLiteral, S extends string = Static<T>> = Ensure<TUnionResult<Assert<UnionToTuple<{
401
+ export type TLiteralUnionReduce<T extends TLiteral<string | number>[]> = T extends [infer L, ...infer R] ? [Assert<L, TLiteral<string | number>>['const'], ...TLiteralUnionReduce<Assert<R, TLiteral<string>[]>>] : [
402
+ ];
403
+ export type TLiteralUnion<T extends TUnion<TLiteral<string | number>[]>> = T extends TUnion<infer S> ? TLiteralUnionReduce<Assert<S, TLiteral<string | number>[]>> : [];
404
+ export type TUnionTemplateLiteral<T extends TTemplateLiteral, S extends string = Static<T>> = Ensure<UnionType<Assert<UnionToTuple<{
381
405
  [K in S]: TLiteral<K>;
382
406
  }[S]>, TLiteral[]>>>;
383
407
  export interface TUnion<T extends TSchema[] = TSchema[]> extends TSchema {
@@ -472,6 +496,14 @@ export declare namespace TypeGuard {
472
496
  function TIntersect(schema: unknown): schema is TIntersect;
473
497
  /** Returns true if the given schema is TKind */
474
498
  function TKind(schema: unknown): schema is Record<typeof Kind | string, unknown>;
499
+ /** Returns true if the given schema is TLiteral<string> */
500
+ function TLiteralString(schema: unknown): schema is TLiteral<string>;
501
+ /** Returns true if the given schema is TLiteral<number> */
502
+ function TLiteralNumber(schema: unknown): schema is TLiteral<number>;
503
+ /** Returns true if the given schema is TLiteral<boolean> */
504
+ function TLiteralBoolean(schema: unknown): schema is TLiteral<boolean>;
505
+ /** Returns true if the given schema is TUnion<Literal<string>[]> */
506
+ function TLiteralUnion(schema: unknown): schema is TUnion<TLiteral<string>[]>;
475
507
  /** Returns true if the given schema is TLiteral */
476
508
  function TLiteral(schema: unknown): schema is TLiteral;
477
509
  /** Returns true if the given schema is TNever */
@@ -504,8 +536,6 @@ export declare namespace TypeGuard {
504
536
  function TUndefined(schema: unknown): schema is TUndefined;
505
537
  /** Returns true if the given schema is TUnion */
506
538
  function TUnion(schema: unknown): schema is TUnion;
507
- /** Returns true if the given schema is TUnion<Literal<string>[]> */
508
- function TUnionLiteral(schema: unknown): schema is TUnion<TLiteral<string>[]>;
509
539
  /** Returns true if the given schema is TUint8Array */
510
540
  function TUint8Array(schema: unknown): schema is TUint8Array;
511
541
  /** Returns true if the given schema is TUnknown */
@@ -540,16 +570,30 @@ export declare namespace TypeClone {
540
570
  /** Clones a type. */
541
571
  function Clone<T extends TSchema>(schema: T, options: SchemaOptions): T;
542
572
  }
573
+ export declare namespace IndexedAccessor {
574
+ function Resolve(schema: TSchema, keys: string[]): TSchema[];
575
+ }
543
576
  export declare namespace ObjectMap {
544
577
  function Map<T = TSchema>(schema: TSchema, callback: (object: TObject) => TObject, options: SchemaOptions): T;
545
578
  }
579
+ export interface KeyResolverOptions {
580
+ includePatterns: boolean;
581
+ }
546
582
  export declare namespace KeyResolver {
547
- function Resolve<T extends TSchema>(schema: T): string[];
583
+ /** Resolves an array of keys in this schema */
584
+ function ResolveKeys(schema: TSchema, options: KeyResolverOptions): string[];
585
+ /** Resolves a regular expression pattern matching all keys in this schema */
586
+ function ResolvePattern(schema: TSchema): string;
587
+ }
588
+ export declare namespace KeyArrayResolver {
589
+ /** Resolves an array of string[] keys from the given schema or array type. */
590
+ function Resolve(schema: TSchema | string[]): string[];
548
591
  }
549
592
  export declare namespace TemplateLiteralPattern {
550
593
  function Create(kinds: TTemplateLiteralKind[]): string;
551
594
  }
552
595
  export declare namespace TemplateLiteralResolver {
596
+ /** Resolves a template literal as a TUnion */
553
597
  function Resolve(template: TTemplateLiteral): TString | TUnion | TLiteral;
554
598
  }
555
599
  export declare class TemplateLiteralParserError extends Error {
@@ -609,6 +653,18 @@ export declare class StandardTypeBuilder extends TypeBuilder {
609
653
  Exclude<L extends TSchema, R extends TSchema>(left: L, right: R, options?: SchemaOptions): TExclude<L, R>;
610
654
  /** `[Standard]` Extracts from the left type any type that is assignable to the right */
611
655
  Extract<L extends TSchema, R extends TSchema>(left: L, right: R, options?: SchemaOptions): TExtract<L, R>;
656
+ /** `[Standard]` Returns indexed property types for the given keys */
657
+ Index<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: [...K], options?: SchemaOptions): TIndex<T, K>;
658
+ /** `[Standard]` Returns indexed property types for the given keys */
659
+ Index<T extends TSchema, K extends TUnion<TLiteral<string | number>[]>>(schema: T, keys: K, options?: SchemaOptions): TIndex<T, TLiteralUnion<K>>;
660
+ /** `[Standard]` Returns indexed property types for the given keys */
661
+ Index<T extends TSchema, K extends TLiteral<string | number>>(schema: T, key: K, options?: SchemaOptions): TIndex<T, [K['const']]>;
662
+ /** `[Standard]` Returns indexed property types for the given keys */
663
+ Index<T extends TSchema, K extends TTemplateLiteral>(schema: T, key: K, options?: SchemaOptions): TIndex<T, TTemplateLiteralKeyArray<K>>;
664
+ /** `[Standard]` Returns indexed property types for the given keys */
665
+ Index<T extends TArray, K extends TNumber>(schema: T, key: K, options?: SchemaOptions): T['items'];
666
+ /** `[Standard]` Returns indexed property types for the given keys */
667
+ Index<T extends TSchema, K extends TNever>(schema: T, key: K, options?: SchemaOptions): TIndex<T, never>;
612
668
  /** `[Standard]` Creates an Integer type */
613
669
  Integer(options?: NumericOptions<number>): TInteger;
614
670
  /** `[Standard]` Creates a Intersect type */
@@ -633,20 +689,24 @@ export declare class StandardTypeBuilder extends TypeBuilder {
633
689
  /** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
634
690
  Omit<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: readonly [...K], options?: SchemaOptions): TOmit<T, K[number]>;
635
691
  /** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
636
- Omit<T extends TSchema, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: SchemaOptions): TOmit<T, TUnionOfLiteral<K>>;
692
+ Omit<T extends TSchema, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: SchemaOptions): TOmit<T, TLiteralUnion<K>[number]>;
637
693
  /** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
638
694
  Omit<T extends TSchema, K extends TLiteral<string>>(schema: T, key: K, options?: SchemaOptions): TOmit<T, K['const']>;
639
695
  /** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
696
+ Omit<T extends TSchema, K extends TTemplateLiteral>(schema: T, key: K, options?: SchemaOptions): TOmit<T, TTemplateLiteralKeyArray<K>[number]>;
697
+ /** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
640
698
  Omit<T extends TSchema, K extends TNever>(schema: T, key: K, options?: SchemaOptions): TOmit<T, never>;
641
699
  /** `[Standard]` Creates a mapped type where all properties are Optional */
642
700
  Partial<T extends TSchema>(schema: T, options?: ObjectOptions): TPartial<T>;
643
701
  /** `[Standard]` Creates a mapped type whose keys are picked from the given type */
644
702
  Pick<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: readonly [...K], options?: SchemaOptions): TPick<T, K[number]>;
645
703
  /** `[Standard]` Creates a mapped type whose keys are picked from the given type */
646
- Pick<T extends TSchema, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: SchemaOptions): TPick<T, TUnionOfLiteral<K>>;
704
+ Pick<T extends TSchema, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: SchemaOptions): TPick<T, TLiteralUnion<K>[number]>;
647
705
  /** `[Standard]` Creates a mapped type whose keys are picked from the given type */
648
706
  Pick<T extends TSchema, K extends TLiteral<string>>(schema: T, key: K, options?: SchemaOptions): TPick<T, K['const']>;
649
707
  /** `[Standard]` Creates a mapped type whose keys are picked from the given type */
708
+ Pick<T extends TSchema, K extends TTemplateLiteral>(schema: T, key: K, options?: SchemaOptions): TPick<T, TTemplateLiteralKeyArray<K>[number]>;
709
+ /** `[Standard]` Creates a mapped type whose keys are picked from the given type */
650
710
  Pick<T extends TSchema, K extends TNever>(schema: T, key: K, options?: SchemaOptions): TPick<T, never>;
651
711
  /** `[Standard]` Creates a Record type */
652
712
  Record<K extends TUnion<TLiteral<string | number>[]>, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): RecordUnionLiteralType<K, T>;
@@ -665,7 +725,7 @@ export declare class StandardTypeBuilder extends TypeBuilder {
665
725
  /** `[Standard]` Creates a mapped type where all properties are Required */
666
726
  Required<T extends TSchema>(schema: T, options?: SchemaOptions): TRequired<T>;
667
727
  /** `[Standard]` Creates a String type */
668
- String<Format extends string>(options?: StringOptions<StringFormatOption | Format>): TString<Format>;
728
+ String(options?: StringOptions): TString;
669
729
  /** `[Standard]` Creates a template literal type */
670
730
  TemplateLiteral<T extends TTemplateLiteralKind[]>(kinds: [...T], options?: SchemaOptions): TTemplateLiteral<T>;
671
731
  /** `[Standard]` Creates a Tuple type */