Getting a type from Zod Schema

Is there a way that I can get a type from a Zod schema? Essentially I want to set the type the return value from a function to the type generated from the Zod schema.
5 Replies
Neto
Neto2y ago
type T = z.infer<typeof schema>
Liam
Liam2y ago
Thanks! @Neto is there a way to do this with a enum? (Essentially convert a Zod enum to a TS enum?)
Neto
Neto2y ago
Maybe
Neto
Neto2y ago
GitHub
GitHub - colinhacks/zod: TypeScript-first schema validation with st...
TypeScript-first schema validation with static type inference - GitHub - colinhacks/zod: TypeScript-first schema validation with static type inference
Leonidas
Leonidas2y ago
Try it out! If i remember correctly a zod enum will be a typescript union type if comverted via z.infer<T>
Want results from more Discord servers?
Add your server