You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have some schemas where I want to accept null as input, and turn that into a default value. I’m generating JSON schemas and documentation from the zod schemas, so the actual .default('default') call is important to set metadata.
Let’s say this is the base schema. I would like this script to log default twice.
I have some schemas where I want to accept
null
as input, and turn that into a default value. I’m generating JSON schemas and documentation from the zod schemas, so the actual.default('default')
call is important to set metadata.Let’s say this is the base schema. I would like this script to log
default
twice.I could do the following:
This works ok. However, this is error prone. I made a typo in the returned value from
transform
. I also need to maintain the default value twice.I see two solutions.
.default()
can accept a second argument. This is a function which returns whether or not the default value should be used.Provide more context to the
.transform()
context, notably a default value.This is especially useful, because it makes the transform function reusable.
The text was updated successfully, but these errors were encountered: