Should I use optional() with default()?
#3864
Unanswered
samuliasmala
asked this question in
Q&A
Replies: 1 comment
-
|
This is now fixed in Zod v4: > z.boolean().optional().default(true).parse()
true
> z.boolean().default(true).optional().parse()
true
> z.boolean().default(true).parse()
true |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
If I specify a default value using
default(), is it unnecessary or even incorrect also specifyoptional()? And a related question: if I putoptional()after thedefault()why I'm not getting the default value (please see the example below)?Beta Was this translation helpful? Give feedback.
All reactions