11import * as schema from '../schema' ;
22import * as classes from './classes' ;
3- import type { Type , TypeOfAlias } from './types' ;
3+ import type { TypeRef , TypeRefToType , Type , TypeOfAlias } from './types' ;
44
55const { s} = schema ;
66
@@ -76,7 +76,7 @@ export class TypeBuilder {
7676
7777 // --------------------------------------------------------------- shorthands
7878
79- public readonly or = < F extends Type [ ] > ( ...types : F ) => this . Or ( ...types ) ;
79+ public readonly or = < F extends TypeRef < any > [ ] > ( ...types : F ) => this . Or ( ...types ) ;
8080 public readonly undefined = ( ) => this . undef ;
8181 public readonly null = ( ) => this . nil ;
8282 public readonly boolean = ( ) => this . bool ;
@@ -94,7 +94,11 @@ export class TypeBuilder {
9494 options ,
9595 ) ;
9696
97- public readonly tuple = < F extends Type [ ] > ( ...types : F ) => this . Tuple ( types ) ;
97+ public readonly tuple = < F extends TypeRef < any > [ ] > ( ...types : F ) => this . Tuple ( types ) ;
98+
99+ protected typeRefToType = < T extends Type > ( type : TypeRef < T > ) : TypeRefToType < T > => {
100+ return typeof type === 'function' ? ( type ( ) as TypeRefToType < T > ) : ( type as TypeRefToType < T > ) ;
101+ } ;
98102
99103 /**
100104 * Creates an object type with the specified properties. This is a shorthand for
@@ -117,10 +121,10 @@ export class TypeBuilder {
117121 * @param record A mapping of property names to types.
118122 * @returns An object type.
119123 */
120- public readonly object = < R extends Record < string , Type > > ( record : R ) : classes . ObjType < RecordToFields < R > > => {
124+ public readonly object = < R extends Record < string , TypeRef < any > > > ( record : R ) : classes . ObjType < RecordToFields < { [ K in keyof R ] : TypeRefToType < R [ K ] > } > > => {
121125 const keys : classes . KeyType < any , any > [ ] = [ ] ;
122- for ( const [ key , value ] of Object . entries ( record ) ) keys . push ( this . Key ( key , value ) ) ;
123- return new classes . ObjType < RecordToFields < R > > ( keys as any ) . sys ( this . system ) ;
126+ for ( const [ key , value ] of Object . entries ( record ) ) keys . push ( this . Key ( key , this . typeRefToType ( value ) ) ) ;
127+ return new classes . ObjType < RecordToFields < { [ K in keyof R ] : TypeRefToType < R [ K ] > } > > ( keys as any ) . sys ( this . system ) ;
124128 } ;
125129
126130 /**
0 commit comments