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
type T = z.infer<typeof schema>
Thanks!
@Neto is there a way to do this with a enum? (Essentially convert a Zod enum to a TS enum?)
Maybe
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
Try it out! If i remember correctly a zod enum will be a typescript union type if comverted via z.infer<T>