@sinclair/typebox 0.31.23 → 0.31.24
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/typebox.d.ts +19 -17
package/package.json
CHANGED
package/typebox.d.ts
CHANGED
|
@@ -104,9 +104,10 @@ export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptio
|
|
|
104
104
|
type: 'array';
|
|
105
105
|
items: T;
|
|
106
106
|
}
|
|
107
|
+
export type TAsyncIteratorResolve<T extends TSchema, P extends unknown[]> = Ensure<AsyncIterableIterator<Static<T, P>>>;
|
|
107
108
|
export interface TAsyncIterator<T extends TSchema = TSchema> extends TSchema {
|
|
108
109
|
[Kind]: 'AsyncIterator';
|
|
109
|
-
static:
|
|
110
|
+
static: TAsyncIteratorResolve<T, this['params']>;
|
|
110
111
|
type: 'AsyncIterator';
|
|
111
112
|
items: T;
|
|
112
113
|
}
|
|
@@ -122,7 +123,7 @@ export interface TBoolean extends TSchema {
|
|
|
122
123
|
static: boolean;
|
|
123
124
|
type: 'boolean';
|
|
124
125
|
}
|
|
125
|
-
export type TConstructorParameters<T extends TConstructor<TSchema[], TSchema>> = TTuple<T['parameters']
|
|
126
|
+
export type TConstructorParameters<T extends TConstructor<TSchema[], TSchema>> = Ensure<TTuple<T['parameters']>>;
|
|
126
127
|
export type TInstanceType<T extends TConstructor<TSchema[], TSchema>> = T['returns'];
|
|
127
128
|
export type TCompositeKeys<T extends TObject[]> = T extends [infer L, ...infer R] ? keyof Assert<L, TObject>['properties'] | TCompositeKeys<Assert<R, TObject[]>> : never;
|
|
128
129
|
export type TCompositeIndex<T extends TIntersect<TObject[]>, K extends string[]> = K extends [infer L, ...infer R] ? {
|
|
@@ -130,12 +131,12 @@ export type TCompositeIndex<T extends TIntersect<TObject[]>, K extends string[]>
|
|
|
130
131
|
} & TCompositeIndex<T, Assert<R, string[]>> : {};
|
|
131
132
|
export type TCompositeReduce<T extends TObject[]> = UnionToTuple<TCompositeKeys<T>> extends infer K ? Evaluate<TCompositeIndex<TIntersect<T>, Assert<K, string[]>>> : {};
|
|
132
133
|
export type TComposite<T extends TObject[]> = TIntersect<T> extends TIntersect ? TObject<TCompositeReduce<T>> : TObject<{}>;
|
|
133
|
-
export type
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
export type TConstructorReturnTypeResolve<T extends TSchema, P extends unknown[]> = Static<T, P>;
|
|
135
|
+
export type TConstructorParametersResolve<T extends TSchema[], P extends unknown[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [Static<L, P>, ...TFunctionParametersResolve<R, P>] : [];
|
|
136
|
+
export type TConstructorResolve<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<new (...param: TConstructorParametersResolve<T, P>) => TConstructorReturnTypeResolve<U, P>>;
|
|
136
137
|
export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
137
138
|
[Kind]: 'Constructor';
|
|
138
|
-
static:
|
|
139
|
+
static: TConstructorResolve<T, U, this['params']>;
|
|
139
140
|
type: 'Constructor';
|
|
140
141
|
parameters: T;
|
|
141
142
|
returns: U;
|
|
@@ -183,12 +184,12 @@ export type TExtractArray<T extends TSchema[], U extends TSchema> = AssertRest<U
|
|
|
183
184
|
[K in keyof T]: Static<AssertType<T[K]>> extends Static<U> ? T[K] : never;
|
|
184
185
|
}[number]>> extends infer R ? UnionType<AssertRest<R>> : never;
|
|
185
186
|
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;
|
|
186
|
-
export type
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
export type TFunctionReturnTypeResolve<T extends TSchema, P extends unknown[]> = Static<T, P>;
|
|
188
|
+
export type TFunctionParametersResolve<T extends TSchema[], P extends unknown[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [Static<L, P>, ...TFunctionParametersResolve<R, P>] : [];
|
|
189
|
+
export type TFunctionResolve<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<(...param: TFunctionParametersResolve<T, P>) => TFunctionReturnTypeResolve<U, P>>;
|
|
189
190
|
export interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
190
191
|
[Kind]: 'Function';
|
|
191
|
-
static:
|
|
192
|
+
static: TFunctionResolve<T, U, this['params']>;
|
|
192
193
|
type: 'Function';
|
|
193
194
|
parameters: T;
|
|
194
195
|
returns: U;
|
|
@@ -223,9 +224,10 @@ export interface TIntersect<T extends TSchema[] = TSchema[]> extends TSchema, In
|
|
|
223
224
|
type?: 'object';
|
|
224
225
|
allOf: [...T];
|
|
225
226
|
}
|
|
227
|
+
export type TIteratorResolve<T extends TSchema, P extends unknown[]> = Ensure<IterableIterator<Static<T, P>>>;
|
|
226
228
|
export interface TIterator<T extends TSchema = TSchema> extends TSchema {
|
|
227
229
|
[Kind]: 'Iterator';
|
|
228
|
-
static:
|
|
230
|
+
static: TIteratorResolve<T, this['params']>;
|
|
229
231
|
type: 'Iterator';
|
|
230
232
|
items: T;
|
|
231
233
|
}
|
|
@@ -443,7 +445,7 @@ export type DecodeProperties<T extends TProperties> = {
|
|
|
443
445
|
[K in keyof T]: DecodeType<T[K]>;
|
|
444
446
|
};
|
|
445
447
|
export type DecodeRest<T extends TSchema[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [DecodeType<L>, ...DecodeRest<R>] : [];
|
|
446
|
-
export type DecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<DecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<DecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<DecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<DecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<P
|
|
448
|
+
export type DecodeType<T extends TSchema> = (T extends TOptional<infer S extends TSchema> ? TOptional<DecodeType<S>> : T extends TReadonly<infer S extends TSchema> ? TReadonly<DecodeType<S>> : T extends TTransform<infer _, infer R> ? TUnsafe<R> : T extends TArray<infer S extends TSchema> ? TArray<DecodeType<S>> : T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<DecodeType<S>> : T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<DecodeRest<P>, DecodeType<R>> : T extends TEnum<infer S> ? TEnum<S> : T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<DecodeRest<P>, DecodeType<R>> : T extends TIntersect<infer S extends TSchema[]> ? TIntersect<DecodeRest<S>> : T extends TIterator<infer S extends TSchema> ? TIterator<DecodeType<S>> : T extends TNot<infer S extends TSchema> ? TNot<DecodeType<S>> : T extends TObject<infer S> ? TObject<Evaluate<DecodeProperties<S>>> : T extends TPromise<infer S extends TSchema> ? TPromise<DecodeType<S>> : T extends TRecord<infer K, infer S> ? TRecord<K, DecodeType<S>> : T extends TRecursive<infer S extends TSchema> ? TRecursive<DecodeType<S>> : T extends TRef<infer S extends TSchema> ? TRef<DecodeType<S>> : T extends TTuple<infer S extends TSchema[]> ? TTuple<DecodeRest<S>> : T extends TUnion<infer S extends TSchema[]> ? TUnion<DecodeRest<S>> : T);
|
|
447
449
|
export type TransformFunction<T = any, U = any> = (value: T) => U;
|
|
448
450
|
export interface TransformOptions<I extends TSchema = TSchema, O extends unknown = unknown> {
|
|
449
451
|
Decode: TransformFunction<StaticDecode<I>, O>;
|
|
@@ -509,11 +511,11 @@ export interface TVoid extends TSchema {
|
|
|
509
511
|
static: void;
|
|
510
512
|
type: 'void';
|
|
511
513
|
}
|
|
512
|
-
/** Creates
|
|
514
|
+
/** Creates an decoded static type from a TypeBox type */
|
|
513
515
|
export type StaticDecode<T extends TSchema, P extends unknown[] = []> = Static<DecodeType<T>, P>;
|
|
514
|
-
/** Creates
|
|
516
|
+
/** Creates an encoded static type from a TypeBox type */
|
|
515
517
|
export type StaticEncode<T extends TSchema, P extends unknown[] = []> = Static<T, P>;
|
|
516
|
-
/** Creates
|
|
518
|
+
/** Creates a static type from a TypeBox type */
|
|
517
519
|
export type Static<T extends TSchema, P extends unknown[] = []> = (T & {
|
|
518
520
|
params: P;
|
|
519
521
|
})['static'];
|
|
@@ -918,7 +920,7 @@ export declare class JavaScriptTypeBuilder extends JsonTypeBuilder {
|
|
|
918
920
|
/** `[JavaScript]` Creates a BigInt type */
|
|
919
921
|
BigInt(options?: NumericOptions<bigint>): TBigInt;
|
|
920
922
|
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
921
|
-
ConstructorParameters<T extends TConstructor<
|
|
923
|
+
ConstructorParameters<T extends TConstructor<TSchema[], TSchema>>(schema: T, options?: SchemaOptions): TConstructorParameters<T>;
|
|
922
924
|
/** `[JavaScript]` Creates a Constructor type */
|
|
923
925
|
Constructor<T extends TSchema[], U extends TSchema>(parameters: [...T], returns: U, options?: SchemaOptions): TConstructor<T, U>;
|
|
924
926
|
/** `[JavaScript]` Creates a Date type */
|
|
@@ -930,7 +932,7 @@ export declare class JavaScriptTypeBuilder extends JsonTypeBuilder {
|
|
|
930
932
|
/** `[JavaScript]` Creates an Iterator type */
|
|
931
933
|
Iterator<T extends TSchema>(items: T, options?: SchemaOptions): TIterator<T>;
|
|
932
934
|
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
933
|
-
Parameters<T extends TFunction<
|
|
935
|
+
Parameters<T extends TFunction<TSchema[], TSchema>>(schema: T, options?: SchemaOptions): TParameters<T>;
|
|
934
936
|
/** `[JavaScript]` Creates a Promise type */
|
|
935
937
|
Promise<T extends TSchema>(item: T, options?: SchemaOptions): TPromise<T>;
|
|
936
938
|
/** `[JavaScript]` Creates a String type from a Regular Expression pattern */
|