Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expose array element validation errors in zod resolver #119

Merged
merged 1 commit into from
Jan 31, 2021

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 !

@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