Handling Missing Values in Zod

From the Zod cheat sheet ยท Optional, Nullable, Default & Catch ยท verified Jul 2026

Handling Missing Values

Optional, nullable, default values, and catch fallbacks

typescript
z.string().optional();   // string | undefined
z.string().nullable();   // string | null
z.string().nullish();    // string | null | undefined
z.string().default("hello");
z.string().catch("fallback");
๐Ÿ’ก .default() only kicks in when the value is undefined, not null
โšก .catch() is like a try/catch โ€” it swallows ALL errors and returns the fallback
๐Ÿ“Œ Use .nullish() for fields that may be null OR undefined (common in databases)
๐ŸŸข .default() with a function generates a fresh value on every parse โ€” ideal for IDs
optionalnullabledefault
Back to the full Zod cheat sheet