Nullable
Wraps a schema to allow null values. Ideal for nullable database fields or optional refs.
Chainable Methods
- Built from inner:
v.null(innerSchema)(note:vNullin code). - Inherits all chains from
innerSchema.
Example
typescript
import { v, Infer } from 'typyn';
const nullAgeSchema = v.null(v.number().min(0));
const age = nullAgeSchema.parse(null); // null (allowed)
const safeAge = nullAgeSchema.safe(-5); // { success: false, error: { path: '', message: 'Must be >= 0' } }
type NullAge = Infer<typeof nullAgeSchema>; // number | nullError Example: Non-null invalid values throw inner error; null always passes.
Back to Utilities | Next: Union
Last updated: October 23, 2025.
