File tree Expand file tree Collapse file tree 5 files changed +48
-4
lines changed
Expand file tree Collapse file tree 5 files changed +48
-4
lines changed Original file line number Diff line number Diff line change @@ -451,3 +451,23 @@ test("passthrough index signature", () => {
451451 type b = z . infer < typeof b > ;
452452 util . assertEqual < { a : string } & { [ k : string ] : unknown } , b > ( true ) ;
453453} ) ;
454+
455+ test ( "xor" , ( ) => {
456+ type Without < T , U > = { [ P in Exclude < keyof T , keyof U > ] ?: never } ;
457+ type XOR < T , U > = T extends object
458+ ? U extends object
459+ ? ( Without < T , U > & U ) | ( Without < U , T > & T )
460+ : U
461+ : T ;
462+
463+ type A = { name : string ; a : number } ;
464+ type B = { name : string ; b : number } ;
465+ type C = XOR < A , B > ;
466+ type Outer = { data : C } ;
467+ const Outer : z . ZodType < Outer > = z . object ( {
468+ data : z . union ( [
469+ z . object ( { name : z . string ( ) , a : z . number ( ) } ) ,
470+ z . object ( { name : z . string ( ) , b : z . number ( ) } ) ,
471+ ] ) ,
472+ } ) ;
473+ } ) ;
Original file line number Diff line number Diff line change @@ -108,6 +108,10 @@ export namespace objectUtil {
108108 [ k in keyof T ] : undefined extends T [ k ] ? never : k ;
109109 } [ keyof T ] ;
110110
111+ // export type addQuestionMarks<
112+ // T extends object,
113+ // R extends keyof T = requiredKeys<T>
114+ // > = Pick<Required<T>, R> & Partial<T>;
111115 export type addQuestionMarks <
112116 T extends object ,
113117 R extends keyof T = requiredKeys < T > ,
Original file line number Diff line number Diff line change 11import { z } from "./src" ;
22
33z ;
4-
5- const schema = z . object ( { name : z . string ( ) } ) . catchall ( z . string ( ) ) ;
6-
7- type schema = z . input < typeof schema > ;
Original file line number Diff line number Diff line change @@ -450,3 +450,23 @@ test("passthrough index signature", () => {
450450 type b = z . infer < typeof b > ;
451451 util . assertEqual < { a : string } & { [ k : string ] : unknown } , b > ( true ) ;
452452} ) ;
453+
454+ test ( "xor" , ( ) => {
455+ type Without < T , U > = { [ P in Exclude < keyof T , keyof U > ] ?: never } ;
456+ type XOR < T , U > = T extends object
457+ ? U extends object
458+ ? ( Without < T , U > & U ) | ( Without < U , T > & T )
459+ : U
460+ : T ;
461+
462+ type A = { name : string ; a : number } ;
463+ type B = { name : string ; b : number } ;
464+ type C = XOR < A , B > ;
465+ type Outer = { data : C } ;
466+ const Outer : z . ZodType < Outer > = z . object ( {
467+ data : z . union ( [
468+ z . object ( { name : z . string ( ) , a : z . number ( ) } ) ,
469+ z . object ( { name : z . string ( ) , b : z . number ( ) } ) ,
470+ ] ) ,
471+ } ) ;
472+ } ) ;
Original file line number Diff line number Diff line change @@ -108,6 +108,10 @@ export namespace objectUtil {
108108 [ k in keyof T ] : undefined extends T [ k ] ? never : k ;
109109 } [ keyof T ] ;
110110
111+ // export type addQuestionMarks<
112+ // T extends object,
113+ // R extends keyof T = requiredKeys<T>
114+ // > = Pick<Required<T>, R> & Partial<T>;
111115 export type addQuestionMarks <
112116 T extends object ,
113117 R extends keyof T = requiredKeys < T > ,
You can’t perform that action at this time.
0 commit comments