Zod
ELI5 — The Vibe Check
Zod is a TypeScript library for validating data at runtime. TypeScript types disappear when your code runs — they only exist at compile time. Zod bridges that gap: you define a schema, and Zod checks actual data against it at runtime AND gives you the TypeScript type for free. One schema, two jobs. It's the 'trust but verify' of TypeScript.
Real Talk
Zod is a TypeScript-first schema declaration and validation library with zero dependencies. It provides runtime validation with automatic TypeScript type inference — define a schema once and get both runtime validation and static types. Zod schemas are composable, immutable, and support complex types (unions, intersections, transforms, refinements). It's the de facto standard for form validation (React Hook Form), API input validation (tRPC, Express), and environment variable parsing.
Show Me The Code
import { z } from 'zod';
const UserSchema = z.object({
name: z.string().min(2),
email: z.string().email(),
age: z.number().int().positive().optional(),
});
// TypeScript type inferred automatically
type User = z.infer<typeof UserSchema>;
// { name: string; email: string; age?: number }
const result = UserSchema.safeParse(formData);
if (!result.success) {
console.log(result.error.issues);
}
When You'll Hear This
"Validate the API input with Zod — never trust client data." / "Zod infers the TypeScript type from the schema — no duplication."
Related Terms
Schema
A database schema is the blueprint of your database — which tables exist, what columns they have, what types they are, and how they relate to each other.
tRPC
tRPC lets you call your backend functions directly from the frontend with full TypeScript type safety — no REST endpoints, no API schema, no code generatio...
TypeScript
TypeScript is JavaScript with a strict parent watching over it.
Validation
Validation is your backend's bouncer. Before any data gets into the database, the bouncer checks it: 'Is this email actually an email?