Skip to content

Utilities

Utilities enhance schemas with optional/nullable unions or choices. They're wrappers around other schemas, adding flexibility without complexity.

Each utility supports:

  • Core Methods: .parse(value) and .safe(value) from the inner schema.
  • Type Inference: Infer<typeof utility> includes the wrapper (e.g., T | undefined for optional).
  • Composition: Nest freely, e.g., v.optional(v.union([v.string(), v.number()])).

Pro Tip: Use for partial objects or dynamic types, like API responses.


Last updated: October 23, 2025.

MIT Licensed | Copyright © 2025 ManojKumar2920