Zod Schema Basics
Define schemas for primitives, objects, and arrays.
Why Runtime Validation?
TypeScript types vanish at runtime. Data from APIs, forms, and files is untyped at the boundary. Zod validates that data at runtime and gives you types too.
import { z } from "zod";
// Types check at compile time; Zod checks values at runtime.Importing Zod
Bring in the z namespace from the zod package. Every schema builder lives on z.
import { z } from "zod";
const nameSchema = z.string();
// nameSchema validates that a value is a string.