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

Silence zod parse error #652

Closed
wants to merge 2 commits into from

Conversation

hunght
Copy link

@hunght hunght commented Oct 19, 2022

No description provided.

Comment on lines +520 to +523
limit: z.preprocess(
(a) => parseInt(z.string().parse(a), 10),
z.number().positive().max(100)
),
Copy link
Owner

Choose a reason for hiding this comment

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

Instead all that, you just need more loose schema in your project, like this one:

z.number().or(
  z.string().transform(
    (str) => parseInt(str, 10)
  )
)

Copy link
Owner

Choose a reason for hiding this comment

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

this way, you accept both number and string, but in any case you supply number to your handler.

@RobinTail
Copy link
Owner

What this PR does is disabling the validation, which is one of the primary goals of the library.
I believe that this does not add value for the users of the library, but it goes against the conceptual intent.
I think the approach should be different, but if still that's what you want for your needs, you can make a fork with this option — the library is open source under MIT license.

@RobinTail RobinTail closed this Oct 19, 2022
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.

2 participants