Skip to content

issue: [zod v4][zod resolver] error on nested discriminated unions #793

@johnyvelho

Description

@johnyvelho

Version Number

5.1.1

Codesandbox/Expo snack

https://codesandbox.io/p/devbox/eager-sun-jt4df-82ptws

Steps to reproduce

  1. open the console in the preview
  2. Submit the form
  3. See error
  4. to make the error goes array, uncomment the line 56

When using Zod resolver and nested discriminated unions, the resolver is not validating the required field before trying to execute the nested discriminated union validations, leaving the error message below:

Uncaught TypeError: Cannot read properties of undefined (reading '0')

Using the @hookform/resolvers/standard-schema works as expected. It validates if the nested discriminated field is filled before going to its validation. But the errors type returns blank as shown in the print below (not sure if this is another bug or expected), and I use it to have a custom map error (z.setErrorMap).

Image

Expected behaviour

work as the parent/root discriminatedUnion, returning the error type invalid_union_discriminator for the field when is not selected

What browsers are you seeing the problem on?

Chrome

Relevant log output

Uncaught TypeError: Cannot read properties of undefined (reading '0')

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions