Zod

A TypeScript library for declaring validation schemas that check data at run time and also produce matching static types.

In more detail

You build a schema from pieces such as z.object, z.string().email() and z.number().int(), then parse data with it. A successful parse returns data you can trust and type; a failure returns a list of issues saying exactly which fields were wrong.

Examples

const UserSchema = z.object({ email: z.string().email(), age: z.number().int().min(18) })
const Charge = z.object({ amount: z.number().positive(), currency: z.enum(['USD', 'EUR']) });
A Next.js Server Action can return Zod's field errors to useActionState to show them in the form.

Related terms

Taught in

References