@@ -935,6 +935,69 @@ expectTypeOf<z.output<typeof _n>>().toEqualTypeOf<number & z.BRAND<"brand">>();
935935expectTypeOf < z . input < typeof _i > > ( ) . toEqualTypeOf < bigint & z . BRAND < "brand" > > ( ) ;
936936expectTypeOf < z . output < typeof _i > > ( ) . toEqualTypeOf < bigint & z . BRAND < "brand" > > ( ) ;
937937
938+ // Test branded objects preserve their brand
939+ const ZBrandedObject = z
940+ . object ( { name : z . string ( ) , age : z . number ( ) } )
941+ . brand < "User" > ( ) ;
942+ const ZBrandedObject2 = z . object ( { id : z . string ( ) } ) . brand ( "UserId" ) ;
943+ const _vBrandedObject = zodToConvex ( ZBrandedObject ) ;
944+ const _vBrandedObject2 = zodToConvex ( ZBrandedObject2 ) ;
945+ const _vBrandedObjectOutput = zodOutputToConvex ( ZBrandedObject ) ;
946+ const _vBrandedObjectOutput2 = zodOutputToConvex ( ZBrandedObject2 ) ;
947+
948+ // Verify branded objects have the brand in their type
949+ type _BrandedObjectType = Infer < typeof _vBrandedObject > ;
950+ type _BrandedObject2Type = Infer < typeof _vBrandedObject2 > ;
951+ type _BrandedObjectOutputType = Infer < typeof _vBrandedObjectOutput > ;
952+ type _BrandedObjectOutput2Type = Infer < typeof _vBrandedObjectOutput2 > ;
953+
954+ expectTypeOf < _BrandedObjectType > ( ) . toEqualTypeOf <
955+ { name : string ; age : number } & z . BRAND < "User" >
956+ > ( ) ;
957+ expectTypeOf < _BrandedObject2Type > ( ) . toEqualTypeOf <
958+ { id : string } & z . BRAND < "UserId" >
959+ > ( ) ;
960+ expectTypeOf < _BrandedObjectOutputType > ( ) . toEqualTypeOf <
961+ { name : string ; age : number } & z . BRAND < "User" >
962+ > ( ) ;
963+ expectTypeOf < _BrandedObjectOutput2Type > ( ) . toEqualTypeOf <
964+ { id : string } & z . BRAND < "UserId" >
965+ > ( ) ;
966+
967+ // Test more complex branded object (like the user's example)
968+ const ZUserBase = z . object ( {
969+ email : z . string ( ) . email ( ) ,
970+ name : z . string ( ) ,
971+ createdAt : z . number ( ) ,
972+ } ) ;
973+ const ZUser = ZUserBase . extend ( {
974+ role : z . enum ( [ "admin" , "user" ] ) ,
975+ } ) . brand < "User" > ( ) ;
976+ const ZUser2 = ZUserBase . extend ( { role : z . enum ( [ "admin" , "user" ] ) } ) . brand (
977+ "User2" ,
978+ ) ;
979+ const _vUser = zodToConvex ( ZUser ) ;
980+ const _vUser2 = zodToConvex ( ZUser2 ) ;
981+
982+ type UserType = Infer < typeof _vUser > ;
983+ type User2Type = Infer < typeof _vUser2 > ;
984+ expectTypeOf < UserType > ( ) . toEqualTypeOf <
985+ {
986+ email : string ;
987+ name : string ;
988+ createdAt : number ;
989+ role : "admin" | "user" ;
990+ } & z . BRAND < "User" >
991+ > ( ) ;
992+ expectTypeOf < User2Type > ( ) . toEqualTypeOf <
993+ {
994+ email : string ;
995+ name : string ;
996+ createdAt : number ;
997+ role : "admin" | "user" ;
998+ } & z . BRAND < "User2" >
999+ > ( ) ;
1000+
9381001function sameType < T , U > ( _t : T , _u : U ) : Equals < T , U > {
9391002 return true as any ;
9401003}
0 commit comments