Yup builds schemas that parse, coerce, and validate values at runtime. Chained methods express required fields, types, conditional rules, and custom tests with structured errors.
Overview
Yup is a schema builder for checking and shaping data as applications run. You define a schema once, then validate inputs, cast unknown values to expected types, or run strict checks on already-parsed data without extra coercion.
Schemas combine transforms that pipeline values through type parsing and optional normalizers with tests that assert business rules transforms cannot represent. Built-in types cover strings, numbers, booleans, dates, arrays, tuples, and nested objects, each with common constraints such as length, format, and range checks.
Objects can be composed, picked, omitted, and extended immutably because each method returns a new schema instance. Conditional branches via when clauses model interdependent fields, and async validation hooks suit client and server flows alike.
TypeScript users can infer output types from schemas or constrain schemas to match existing interfaces. Errors surface as detailed validation error objects suitable for localization helpers, and the library aligns with the Standard Schema interface for interoperability.
Key features
- Chainable schema definitions
- Parse transforms and assertion tests
- Async validate and isValid helpers
- TypeScript type inference support
- Conditional when branches
- Immutable composable schemas
- Custom methods and locales
- Standard Schema compatibility
Use cases
- HTML form field validation
- API request body checking
- Config or env parsing
- Nested object shape guards
- Shared client-server rules