Recursively Unwrapping a Schema in Zod 4 #5191
Replies: 1 comment
-
|
Your first assumption—that every schema in Zod 4 is an instance of Regarding your second assumption about
So, either Additionally, the In summary:
📚 Sources: Have another question? Just tag @inkeep. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working on an app where we need to preprocess data before it is passed to a Zod schema. The preprocessing depends on the schema. It's a weird use case, I know, but we've successfully used this approach with v3 for a long time, and refactoring would be a major pain.
So anyway, I came up with this solution:
This, of course, makes two assumptions I'm not entirely sure are correct:
z.ZodType.inoroutof az.ZodPipecreated by preprocess and transform is always az.ZodTransform, and the other is az.ZodType.Are these assumptions correct? Is there something else that can be improved?
Thank you for your help ✌️
EDIT: I'm aware that we can manually create a
z.ZodPipewhereinandoutare both az.ZodType:but fortunately that isn't relevant for us.
Beta Was this translation helpful? Give feedback.
All reactions