TypeScript · Middle · Question 57 of 75
How do you derive a TypeScript type from a Zod schema?
const User = z.object({ id: z.string(), age: z.number() });
type User = z.infer<typeof User>;- ✓Correct answer: With
z.infer<typeof Schema>- one source of truth for runtime validation and static types - 2Zod generates
.d.tsfiles during build - 3You must write the type manually and keep it in sync
Explanation
Validation at the boundary (API, forms) plus inferred types avoids drift between runtime checks and compile-time types.