Skip to content

z.ZodSchema Questions #794

Answered by JacobWeisenburger
nahtnam asked this question in Q&A
Discussion options

You must be logged in to vote

I noticed that here: dashboards?: Dashboard[]; I have to put a ? because there is default option provided. Is this expected behavior? I understand if it is but then it means that .default and .optional are similar and maybe the docs should note that? Any alternate solutions?

If you have a required field, then giving it a default value doesn't make any sense. Because, by definition, a required field always needs to be passed into parse or it will throw an error. So defining a default value would only ever make sense if that field was optional. So the docs could be updated to be more explicit about this, but I don't think it is entirely necessary.


I noticed that any optional values such…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nahtnam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants