Skip to content

Primitives ​

Primitives form the foundation of Typyn schemas. They handle basic types like strings, numbers, and booleans with chainable constraints for validation, transformation, and defaults.

Each primitive schema supports:

  • Core Methods: .parse(value) (throws on error) and .safe(value) (returns { success, data } | { success: false, error }).
  • Common Chains: .default(val), .refine(fn, msg), .transform(fn).
  • Type Inference: Full TS support—Infer<typeof schema> extracts the validated type.
  • String – Length, patterns, email/URL.
  • Number – Ranges, integers, signs.
  • Boolean – Simple flags with defaults.
  • Literal – Exact value matching.
  • Enum – Union from array of values.

Pro Tip: Start with primitives, then compose into Objects or Arrays.


Last updated: October 23, 2025.

MIT Licensed | Copyright © 2025 ManojKumar2920