Treat null/undefined and “absence vs presence” as first-class concerns.
strictNullChecks is enabled and not overridden by extended configs (explicitly set it to true if needed).undefined vs when it is a wrong value or null.
.default(value) for absent inputs (typically undefined)..catch(fallback) for parsing failures (including wrong strings), not as a substitute for handling undefined."" for an “empty” required field; z.string() will accept "" as a valid string. If you require non-empty content, validate it explicitly (e.g., .min(1)).Example:
import { z } from "zod";
const boolSchema = z.string().boolean();
// absent (undefined) -> fallback
const withDefault = boolSchema.default(false);
// wrong value (including "other" / null if you pass it in) -> fallback
const withCatch = boolSchema.catch(false);
// non-empty string required by UI
const requiredText = z.string().min(1, "Required");
Apply these consistently so validation behavior matches what your types and UI expectations actually mean.
Enter the URL of a public GitHub repository