Preprocess (refine/transform) -> refine.transform.pipe
Here a slightly different suggestion: You could use a
z.string().refine().transform().pipe(z.object({}))
to make it a little more declarative and to rely on the Zod error reporting features in your "preprocessing" part.3 Replies
One potential caveat is that errors in piped schemas get reported for each schema in order, so you wouldn't get the int/min/max errors until the string was properly formatted.
do you mean something like this?
i'm not sure I understand what
pipe()
does though
oh i understand
that's it, right?
Exactly.
You can move your min/max checking into your superRefine and then you don't even really need the
z.object
, but depending on your use case, it's nice to have the z.object
for other things.