@sinclair/typebox 0.30.0-dev-6 → 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.
- package/package.json +1 -1
- package/typebox.d.ts +13 -13
package/package.json
CHANGED
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 */
|
|
@@ -191,14 +190,14 @@ export interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema =
|
|
|
191
190
|
parameters: T;
|
|
192
191
|
returns: U;
|
|
193
192
|
}
|
|
194
|
-
export type TIndexRest<T extends TSchema[], K extends
|
|
195
|
-
export type TIndexProperty<T extends TProperties, K extends
|
|
196
|
-
export type TIndexTuple<T extends TSchema[], K extends
|
|
197
|
-
export type TIndexType<T extends TSchema, K extends
|
|
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>>>> : [
|
|
198
197
|
];
|
|
199
|
-
export type TIndexRestMany<T extends TSchema, K extends
|
|
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[]>>] : [
|
|
200
199
|
];
|
|
201
|
-
export type TIndex<T extends TSchema, K extends
|
|
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;
|
|
202
201
|
export interface TInteger extends TSchema, NumericOptions<number> {
|
|
203
202
|
[Kind]: 'Integer';
|
|
204
203
|
static: number;
|
|
@@ -271,7 +270,8 @@ export type PropertiesReducer<T extends TProperties, R extends Record<keyof any,
|
|
|
271
270
|
export type PropertiesReduce<T extends TProperties, P extends unknown[]> = PropertiesReducer<T, {
|
|
272
271
|
[K in keyof T]: Static<T[K], P>;
|
|
273
272
|
}>;
|
|
274
|
-
export type
|
|
273
|
+
export type TPropertyKey = string | number;
|
|
274
|
+
export type TProperties = Record<TPropertyKey, TSchema>;
|
|
275
275
|
export type ObjectProperties<T> = T extends TObject<infer U> ? U : never;
|
|
276
276
|
export type ObjectPropertyKeys<T> = T extends TObject<infer U> ? keyof U : never;
|
|
277
277
|
export type TAdditionalProperties = undefined | TSchema | boolean;
|
|
@@ -405,7 +405,7 @@ export type TTemplateLiteralConst<T, Acc extends string> = T extends TUnion<infe
|
|
|
405
405
|
[K in keyof U]: TTemplateLiteralUnion<Assert<[U[K]], TTemplateLiteralKind[]>, Acc>;
|
|
406
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;
|
|
407
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;
|
|
408
|
-
export type TTemplateLiteralKeyRest<T extends TTemplateLiteral> = Assert<UnionToTuple<Static<T>>,
|
|
408
|
+
export type TTemplateLiteralKeyRest<T extends TTemplateLiteral> = Assert<UnionToTuple<Static<T>>, TPropertyKey[]>;
|
|
409
409
|
export interface TTemplateLiteral<T extends TTemplateLiteralKind[] = TTemplateLiteralKind[]> extends TSchema {
|
|
410
410
|
[Kind]: 'TemplateLiteral';
|
|
411
411
|
static: TTemplateLiteralUnion<T>;
|
|
@@ -621,7 +621,7 @@ export declare namespace TypeClone {
|
|
|
621
621
|
function Clone<T extends TSchema>(schema: T, options?: SchemaOptions): T;
|
|
622
622
|
}
|
|
623
623
|
export declare namespace IndexedAccessor {
|
|
624
|
-
function Resolve(schema: TSchema, keys:
|
|
624
|
+
function Resolve(schema: TSchema, keys: TPropertyKey[], options?: SchemaOptions): TSchema;
|
|
625
625
|
}
|
|
626
626
|
export declare namespace ObjectMap {
|
|
627
627
|
function Map<T = TSchema>(schema: TSchema, callback: (object: TObject) => TObject, options: SchemaOptions): T;
|
|
@@ -721,11 +721,11 @@ export declare class StandardTypeBuilder extends TypeBuilder {
|
|
|
721
721
|
/** `[Standard]` Returns an Indexed property type for the given keys */
|
|
722
722
|
Index<T extends TSchema, K extends TTemplateLiteral>(schema: T, keys: K, options?: SchemaOptions): TIndex<T, TTemplateLiteralKeyRest<K>>;
|
|
723
723
|
/** `[Standard]` Returns an Indexed property type for the given keys */
|
|
724
|
-
Index<T extends TSchema, K extends TLiteral<
|
|
724
|
+
Index<T extends TSchema, K extends TLiteral<TPropertyKey>>(schema: T, keys: K, options?: SchemaOptions): TIndex<T, [K['const']]>;
|
|
725
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,
|
|
726
|
+
Index<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: [...K], options?: SchemaOptions): TIndex<T, Assert<K, TPropertyKey[]>>;
|
|
727
727
|
/** `[Standard]` Returns an Indexed property type for the given keys */
|
|
728
|
-
Index<T extends TSchema, K extends TUnion<TLiteral<
|
|
728
|
+
Index<T extends TSchema, K extends TUnion<TLiteral<TPropertyKey>[]>>(schema: T, keys: K, options?: SchemaOptions): TIndex<T, TUnionLiteralKeyRest<K>>;
|
|
729
729
|
/** `[Standard]` Returns an Indexed property type for the given keys */
|
|
730
730
|
Index<T extends TSchema, K extends TSchema>(schema: T, key: K, options?: SchemaOptions): TSchema;
|
|
731
731
|
/** `[Standard]` Creates an Integer type */
|