Zod question: How do you keep Zod and TypeScript in sync


Zod question:

How do you keep Zod and TypeScript in sync?

2 options:
1. Derive TS types from your Zod schemas (via infer)
2. Generate Zod schemas from your TS types? (via ts-to-zod)

How do you pick between these 2 options?

cc @colinhacks @alexdotjs @mattpocockuk
Lots of good info in the thread, but to summarize, here's my Zod workflow:

1. Create Zod schemas for types that need runtime validation (e.g. form inputs, API responses)

2. Derive types from the Zod schemas created in step 1 via infer

3. Create TS types for everything else

View original on X