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
My personal opinion, though, is that this is not so easy to implement, and I don't think this lines up with Zod's principles.
Each one of Zod's subclasses implements its own _parse method, which is what controls how the parsing will work for this class specifically. Zod deep clones the input value because ZodArray computes each value individually, as well as ZodTuple, ZodObject etc. Adding a shallow option to parse() means adding a check to each one of the subclasses to tell them not to compute each value separately and instead iterate through the items/properties of the input without reassigning them to a result variable.
This will require adding checks to many subclasses, and then people extending Zod with their own subclasses will have to worry about this as well.
Additionally, some types of input require cloning, e.g., functions when parsed with ZodFunction, or Promises w/ ZodPromise. Parsing here happens on a secondary moment (when the function gets called/Promise gets resolved). I'm not sure there's a clear way of making this shallow option work reliably for all types.
But, well, as always, feel free to open a PR if you feel strong about this. PRs are always welcomed.
I want to use zod and immer together, but zod's
parse
method makes a deep clone of the passed variable and messes up immer'sproduce
method result.Can we add a
shallow: boolean
option to parse methods options to avoid this? Or a deep clone is absolutely necessary?The text was updated successfully, but these errors were encountered: