Skip to content

Conversation

@aprilrd
Copy link
Contributor

@aprilrd aprilrd commented Jan 31, 2021

Issue

I noticed that the errors for array elements are not exposed in the Zod resolver. In the current version, the error looks like this instead (notice it doesn't expose the index of the validation error):

    "likedUsers": Object {
      "message": "Invalid input",
      "type": "invalid_union",
      "types": Object {
        "invalid_union": "Invalid input",
      },
    },

Changes

  • I updated the resolver to look at unionErrors when parsing errors from Zod to fix this error. Only ZodInvalidUnionError can have other errors as field values. So checking the existence of unionErrors should be good enough. But I am open to ideas here.

  • I changed the original code's reduce to a queue to handle deeply nested union errors.

Copy link
Member

@jorisre jorisre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch ! Thanks @aprilrd !

@jorisre jorisre requested a review from bluebill1049 January 31, 2021 21:01
@bluebill1049
Copy link
Member

Thanks, @aprilrd!

@bluebill1049 bluebill1049 merged commit ecee1e9 into react-hook-form:master Jan 31, 2021
@github-actions
Copy link
Contributor

🎉 This PR is included in version 1.3.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@aprilrd
Copy link
Contributor Author

aprilrd commented Feb 1, 2021

I appreciate the quick review and the release 😄

This was referenced Feb 2, 2021
@github-actions
Copy link
Contributor

🎉 This PR is included in version 2.0.0-beta.14 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants