The Input is Different than the Output
We've reached the point with Zod where our input is different than our output.
In other words, you can generate types based on input as well as generating types based on the output.
For example, let's create FormInput
and FormOutput
types:
type FormInput = z.infer<typeof Form>
type FormOutput = z.infer<typeof Form>
Introducing z.input
As written above, the input is not quite correct because when we input into validateFormInput
, we don't need to pass in any keywords.
Instead, we can update the the FormInput
to use z.input
instead of z.infer
.
This gives us a way to slightly tweak the types we generate if there is a difference between the input and output of our validator.
标签:Typescript,Zod,FormInput,our,input,infer,types From: https://www.cnblogs.com/Answer1215/p/18621064