Passthrough output typing #1345
Unanswered
iambryanhaney
asked this question in
Q&A
Replies: 1 comment
-
I know this is a late reply, but stumbled across this post while looking for a related discussion.
Doesn't this seem desirable, though? Presumably, you're saving the values of steps one and two somewhere, and so there's a non-zero chance of that data changing between now and then. 🙂 If it has changed, handle that logic by passing your user back to that failed step. If there are lots of async checks, cache them locally in a value-keyed store somewhere. |
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
-
A zod schema can forward unknown keys to its output via
.passthrough()
, but TS won't know about them inz.output<typeof schema>
(as expected - how would it?).In the context of a multi-step form wizard, in order to aggregate a final output type, one could specify each schema as a merge of the previous, i.e.:
... but that would re-run validations on known-valid fields at each step. To avoid this, you could do something along the lines of:
Alternatively, if you didn't want the intermediate
payload
variable:This solution feels kind of ok but also kind of bloated + antipattern to me.
It would be nice if there was something like a
z.sequence()
that enables passthrough and aggregates output:I can see that as being a bit out of zod's intended scope, so I'm mostly just talking out loud and seeing if anyone has suggestions for a cleaner solution?
Beta Was this translation helpful? Give feedback.
All reactions