Skip to content

coerce.boolean incorrect #3329

Answered by vtgn
lacherogwu asked this question in Q&A
Discussion options

You must be logged in to vote

No, you are wrong.
This is normal that coerce method uses the standard javascript conversions rules.

Go read the documentation: https://zod.dev/?id=coercion-for-primitives
Particularly this part:

This is exactly what I explained to you.

If you find these rules illogical, go blame javascript specification writers. ;)
But if you want different conversion rules, you'll have to implement them yourself like in my previous example.

Regards.

Replies: 7 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by JacobWeisenburger
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #3328 on March 15, 2024 16:11.