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

Provide an alternative mechanism for checking ZodType in parsers #32

Closed
wants to merge 1 commit into from
Closed

Conversation

ghost
Copy link

@ghost ghost commented Mar 5, 2023

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Issue

This original issue - #12

Testing Remix Loaders with Vitest sometimes produces the following error:

TypeError: keyValidator._parse is not a function

The issue appears to be a result of using instanceof to check an object is of a ZodType class. However, during a Vitest build this class is duplicated, meaning instanceof is performed against a unrelated class. (An explanation of this can be found in the comments for the original issue).

Proposal

This PR implements the proposed solution from @taternz #12 (comment), providing an alternative way to check for an object is an instance of the ZodType class.

Obviously this is only a very superficial check to see that the object we receive contains a parse method. An alternative could be to do a shallow comparison of the Object.keys to determine object equality?

@rileytomasek
Copy link
Owner

Thanks for the PR and sorry for the slow response. While not ideal, I'm ok with this approach if you also check safeParse, safeParseAsync, and parseAsync for completeness. If you update the PR I'll merge and cut a new release.

@ghost ghost closed this by deleting the head repository Apr 18, 2023
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant