Parse schema based on input shape #3438
Unanswered
BrendanC23
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a schema that represents the fields of a form. It has an input type and output type, which from from
z.input<>
andz.output<>
. When the form is submitted, the data is parsed usingSchema.parse()
, and the result has the output type. This works well.I want to implement auto-save in the form, which involves storing a partially-complete representation of the form in a database. When the JSON is read from the database, it is type
unknown
. As the form is incomplete, I can't useSchema.parse()
because some fields aren't filled out.I'd like to use Zod to ensure that the saved JSON matches the form's input shape.
Is there a way to parse something against the
z.input<>
type? Something like this:Beta Was this translation helpful? Give feedback.
All reactions