Calling .merge() after refining an object #1862
Unanswered
ravinggenius
asked this question in
Q&A
Replies: 1 comment
-
Is there any update on this? I'm facing the exact same issue. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How can I merge two schemas if I call
.refine()
on one first? I know.refine()
actually returnsZodEffect
, notZodObject
, but I seem to be able to treat the effects as a schema, at least for my purposes (.parse()
). First some code:I want to parse all the attrs together because I want to present all validation errors at once, plus conceptually it makes sense to me. However from a security perspective, I want to keep the schemas and data for
password
/passwordConfirmation
separate from the rest of the attributes.The problem I'm having is
.merge()
doesn't likeUSER_PASSWORD_ATTRS
unless I remove the refinement. Why can't I merge a schema with an effect? Actually for that matter, why does.refine()
have to returnZodEffect
? Why can't it return the type of schema it is given?Right now the only way I can think to solve this is to move the password refinement into the
create
function after merging the two schemas, which I don't like. (For one thing I'll have to remember to add the refinement everywhere I want to useUSER_PASSWORD_ATTRS
.) If you have a better solution, please let me know.Beta Was this translation helpful? Give feedback.
All reactions