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
4343 message : 'Invalid date' ,
4444 } ) ,
4545 ) ,
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+ ] ) ,
4655 } )
4756 . check (
4857 z . refine ( ( obj ) => obj . password === obj . repeatPassword , {
@@ -68,6 +77,10 @@ export const validData = {
6877 } ,
6978 ] ,
7079 dateStr : '2020-01-01' ,
80+ auth : {
81+ type : 'registered' ,
82+ passwordHash : 'hash' ,
83+ } ,
7184} satisfies z . input < typeof schema > ;
7285
7386export const invalidData = {
@@ -76,6 +89,7 @@ export const invalidData = {
7689 birthYear : 'birthYear' ,
7790 like : [ { id : 'z' } ] ,
7891 url : 'abc' ,
92+ auth : { type : 'invalid' } ,
7993} as unknown as z . input < typeof schema > ;
8094
8195export const fields : Record < InternalFieldName , Field [ '_f' ] > = {
Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ function parseZod4Issues(
9191 const _path = path . join ( '.' ) ;
9292
9393 if ( ! errors [ _path ] ) {
94- if ( error . code === 'invalid_union' ) {
94+ if ( error . code === 'invalid_union' && error . errors . length > 0 ) {
9595 const unionError = error . errors [ 0 ] [ 0 ] ;
9696
9797 errors [ _path ] = {
You can’t perform that action at this time.
0 commit comments