File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,15 @@ export const schema = z
43
43
message : 'Invalid date' ,
44
44
} ) ,
45
45
) ,
46
+ auth : z . discriminatedUnion ( 'type' , [
47
+ z . object ( {
48
+ type : z . literal ( 'registered' ) ,
49
+ passwordHash : z . string ( ) ,
50
+ } ) ,
51
+ z . object ( {
52
+ type : z . literal ( 'guest' ) ,
53
+ } ) ,
54
+ ] ) ,
46
55
} )
47
56
. check (
48
57
z . refine ( ( obj ) => obj . password === obj . repeatPassword , {
@@ -68,6 +77,10 @@ export const validData = {
68
77
} ,
69
78
] ,
70
79
dateStr : '2020-01-01' ,
80
+ auth : {
81
+ type : 'registered' ,
82
+ passwordHash : 'hash' ,
83
+ } ,
71
84
} satisfies z . input < typeof schema > ;
72
85
73
86
export const invalidData = {
@@ -76,6 +89,7 @@ export const invalidData = {
76
89
birthYear : 'birthYear' ,
77
90
like : [ { id : 'z' } ] ,
78
91
url : 'abc' ,
92
+ auth : { type : 'invalid' } ,
79
93
} as unknown as z . input < typeof schema > ;
80
94
81
95
export const fields : Record < InternalFieldName , Field [ '_f' ] > = {
Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ function parseZod4Issues(
91
91
const _path = path . join ( '.' ) ;
92
92
93
93
if ( ! errors [ _path ] ) {
94
- if ( error . code === 'invalid_union' ) {
94
+ if ( error . code === 'invalid_union' && error . errors . length > 0 ) {
95
95
const unionError = error . errors [ 0 ] [ 0 ] ;
96
96
97
97
errors [ _path ] = {
You can’t perform that action at this time.
0 commit comments