@@ -7,24 +7,22 @@ import type {TypeOfAlias} from '../system/types';
77
88const { s} = schema ;
99
10- type UnionToIntersection < U > = (
11- U extends never ? never : ( arg : U ) => never
12- ) extends ( arg : infer I ) => void
13- ? I
14- : never ;
15-
16- type UnionToTuple < T > = UnionToIntersection <
17- T extends never ? never : ( t : T ) => T
18- > extends ( _ : never ) => infer W
10+ type UnionToIntersection < U > = ( U extends never ? never : ( arg : U ) => never ) extends ( arg : infer I ) => void ? I : never ;
11+
12+ type UnionToTuple < T > = UnionToIntersection < T extends never ? never : ( t : T ) => T > extends ( _ : never ) => infer W
1913 ? [ ...UnionToTuple < Exclude < T , W > > , W ]
2014 : [ ] ;
2115
22- type ObjValueTuple < T , KS extends any [ ] = UnionToTuple < keyof T > , R extends any [ ] = [ ] > =
23- KS extends [ infer K , ...infer KT ]
16+ type ObjValueTuple < T , KS extends any [ ] = UnionToTuple < keyof T > , R extends any [ ] = [ ] > = KS extends [
17+ infer K ,
18+ ...infer KT ,
19+ ]
2420 ? ObjValueTuple < T , KT , [ ...R , T [ K & keyof T ] ] >
25- : R
21+ : R ;
2622
27- type RecordToFields < O extends Record < string , Type > > = ObjValueTuple < { [ K in keyof O ] : classes . ObjectFieldType < K extends string ? K : never , O [ K ] > } > ;
23+ type RecordToFields < O extends Record < string , Type > > = ObjValueTuple < {
24+ [ K in keyof O ] : classes . ObjectFieldType < K extends string ? K : never , O [ K ] > ;
25+ } > ;
2826
2927export class TypeBuilder {
3028 constructor ( public system ?: TypeSystem ) { }
@@ -79,7 +77,6 @@ export class TypeBuilder {
7977 return this . Function$ ( this . undef , this . undef ) ;
8078 }
8179
82-
8380 // --------------------------------------------------------------- shorthands
8481
8582 public readonly undefined = ( ) => this . undef ;
@@ -94,7 +91,10 @@ export class TypeBuilder {
9491 public readonly literal = this . con ;
9592
9693 public readonly array = < T > ( type ?: T , options ?: schema . Optional < schema . ArraySchema > ) =>
97- this . Array < T extends Type ? T : classes . AnyType > ( ( type ?? this . any ) as T extends Type ? T : classes . AnyType , options ) ;
94+ this . Array < T extends Type ? T : classes . AnyType > (
95+ ( type ?? this . any ) as T extends Type ? T : classes . AnyType ,
96+ options ,
97+ ) ;
9898
9999 public readonly tuple = < F extends Type [ ] > ( ...types : F ) => this . Tuple ( ...types ) ;
100100
@@ -131,8 +131,7 @@ export class TypeBuilder {
131131 * Creates a type that represents a value that may be present or absent. The
132132 * value is `undefined` if absent. This is a shorthand for `t.Or(type, t.undef)`.
133133 */
134- public readonly maybe = < T extends Type > ( type : T ) =>
135- this . Or ( type , this . undef ) ;
134+ public readonly maybe = < T extends Type > ( type : T ) => this . Or ( type , this . undef ) ;
136135
137136 /**
138137 * Creates a union type from a list of values. This is a shorthand for
@@ -147,9 +146,10 @@ export class TypeBuilder {
147146 * @param values The values to include in the union.
148147 * @returns A union type representing the values.
149148 */
150- public readonly enum = < const T extends ( string | number | boolean | null ) [ ] > ( ...values : T ) : classes . OrType < { [ K in keyof T ] : classes . ConstType < schema . Narrow < T [ K ] > > } > =>
151- this . Or ( ...values . map ( type => this . Const ( type as any ) ) ) as any ;
152-
149+ public readonly enum = < const T extends ( string | number | boolean | null ) [ ] > (
150+ ...values : T
151+ ) : classes . OrType < { [ K in keyof T ] : classes . ConstType < schema . Narrow < T [ K ] > > } > =>
152+ this . Or ( ...values . map ( ( type ) => this . Const ( type as any ) ) ) as any ;
153153
154154 // --------------------------------------------------- base node constructors
155155
@@ -246,13 +246,21 @@ export class TypeBuilder {
246246 return type ;
247247 }
248248
249- public Function < Req extends Type , Res extends Type > ( req : Req , res : Res , options ?: schema . Optional < schema . FunctionSchema > ) {
249+ public Function < Req extends Type , Res extends Type > (
250+ req : Req ,
251+ res : Res ,
252+ options ?: schema . Optional < schema . FunctionSchema > ,
253+ ) {
250254 const fn = new classes . FunctionType < Req , Res > ( req , res , options ) ;
251255 fn . system = this . system ;
252256 return fn ;
253257 }
254258
255- public Function$ < Req extends Type , Res extends Type > ( req : Req , res : Res , options ?: schema . Optional < schema . FunctionStreamingSchema > ) {
259+ public Function$ < Req extends Type , Res extends Type > (
260+ req : Req ,
261+ res : Res ,
262+ options ?: schema . Optional < schema . FunctionStreamingSchema > ,
263+ ) {
256264 const fn = new classes . FunctionStreamingType < Req , Res > ( req , res , options ) ;
257265 fn . system = this . system ;
258266 return fn ;
0 commit comments