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
Alternatively, the Schema could be created as a ZodObject and exported as such, and then the ZodType exported separately. This way we can do what we want with the schema or export it as a type. Best of both worlds.
Problem
Generated schemas are not reusable (pick/omit/extend/etc) because the schema infers a type and is not considered a ZodObject anymore. An example...
In the above, it is impossible to use
TodoCreateInput.extend()
, etc because the type z.ZodType<...> is being inferred.Suggested solution
There was a similar discussion in the Zod repo in 1192 and a solution in 1495.
One solution is to change the example above to resolve like the one below. I haven't fully tested this but it seems to work with my simple examples:
Alternatives
Alternatively, the Schema could be created as a ZodObject and exported as such, and then the ZodType exported separately. This way we can do what we want with the schema or export it as a type. Best of both worlds.
Additional context
No other context.
The text was updated successfully, but these errors were encountered: