Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions zod/src/__tests__/__fixtures__/data-v4-mini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ export const schema = z
message: 'Invalid date',
}),
),
auth: z.discriminatedUnion('type', [
z.object({
type: z.literal('registered'),
passwordHash: z.string(),
}),
z.object({
type: z.literal('guest'),
}),
]),
})
.check(
z.refine((obj) => obj.password === obj.repeatPassword, {
Expand All @@ -68,6 +77,10 @@ export const validData = {
},
],
dateStr: '2020-01-01',
auth: {
type: 'registered',
passwordHash: 'hash',
},
} satisfies z.input<typeof schema>;

export const invalidData = {
Expand All @@ -76,6 +89,7 @@ export const invalidData = {
birthYear: 'birthYear',
like: [{ id: 'z' }],
url: 'abc',
auth: { type: 'invalid' },
} as unknown as z.input<typeof schema>;

export const fields: Record<InternalFieldName, Field['_f']> = {
Expand Down
2 changes: 1 addition & 1 deletion zod/src/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function parseZod4Issues(
const _path = path.join('.');

if (!errors[_path]) {
if (error.code === 'invalid_union') {
if (error.code === 'invalid_union' && error.errors.length > 0) {
const unionError = error.errors[0][0];

errors[_path] = {
Expand Down