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
But I want this .nullable().catch() on any field recursively and it makes the code ugly. Any suggestion? it also should be valid for arrays, actually anything. Array example: z.array(z.string()) and array [1, "x", "y"] should be transformed to [null, "x", "y"]
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Given a schema, of any type you can think of, I want to fallback any error to
null
value.That means, given this schema:
and given this code:
The console result should be
Because
x4
should be of typenumber
but was wrong type, therefore "fallbacked" tonull
value. Of course I could do:But I want this
.nullable().catch()
on any field recursively and it makes the code ugly. Any suggestion? it also should be valid for arrays, actually anything. Array example:z.array(z.string())
and array[1, "x", "y"]
should be transformed to[null, "x", "y"]
Beta Was this translation helpful? Give feedback.
All reactions