Zod is the de-facto validation library in the TypeScript ecosystem. Its vocabulary for schemas, parsing, refinements, and type inference appears in code reviews and API design discussions.
0 / 5 completed
1 / 5
A developer says: 'Define the schema with Zod rather than TypeScript types alone.' What does a Zod schema provide beyond types?
TypeScript types are compile-time only — they disappear at runtime. A Zod schema validates actual data at runtime: z.string().email() checks that a value is not only a string but a valid email. Zod also infers TypeScript types from schemas (z.infer<typeof schema>). In discussions: 'use Zod' means you want both compile-time typing AND runtime validation at system boundaries (API inputs, env vars).
2 / 5
A PR comment says: 'Use z.parse() vs z.safeParse() depending on whether you want to throw.' What is the difference?
z.parse(data) throws a ZodError if validation fails — good for server-side validation where failure is unexpected. z.safeParse(data) returns { success: true, data } or { success: false, error } without throwing — better for user input where failure is expected. In discussions: 'use safeParse for form inputs, parse for environment variables' is a common pattern.
3 / 5
A developer says: 'Add a refinement to validate that the end date is after the start date.' What is a Zod refinement?
Zod's .refine(fn, message) adds custom validation logic: z.object({ start: z.date(), end: z.date() }).refine(d => d.end > d.start, 'End must be after start'). Refinements run after built-in type checks. In code reviews: 'add a refinement' means the basic type check isn't enough — you need domain-specific validation logic that Zod can't express with primitives alone.
4 / 5
A developer says: 'Use z.discriminatedUnion() for this tagged union.' What is a discriminated union?
A discriminated union has a shared field (discriminant) that identifies which variant applies: { type: 'error', message: string } | { type: 'success', data: T }. Zod's z.discriminatedUnion('type', [...]) is more efficient than z.union() because it uses the discriminant to determine which schema to check first, avoiding unnecessary validation attempts. Common in API response types with success/error shapes.
5 / 5
A developer says: 'Use z.infer<typeof schema> to get the TypeScript type from the schema.' What does this mean?
z.infer<typeof MySchema> is a TypeScript utility that derives the TypeScript type from a Zod schema. Instead of defining both a TypeScript type AND a Zod schema separately, you define the Zod schema once and extract the type: type User = z.infer<typeof UserSchema>. This eliminates duplication. In discussions: 'use z.infer instead of a separate interface' means the Zod schema is the single source of truth.