
Yup
A JavaScript/TypeScript library for defining schemas that validate and convert data at runtime.
- Stars
- 23.7k
- Forks
- 958
- Licence
- MIT
- Language
- TypeScript
- Last update
- 6 days ago
- Type
- Library
What it is
Yup lets you describe the expected shape of a value, such as a user object with a name, age, and email, using chained method calls. You can then check incoming data against that schema, or convert ('cast') it into the correct types. It is commonly used to check form input or API data before using it.
- Validate a user object so that name is required and age must be a positive integer
- Cast a string such as '24' into the number 24 before using it
- Infer a TypeScript type directly from a schema with InferType
- Run async validation of values, such as checking data on a server
- Add custom validation tests and error messages to schemas
Great for
- Developers validating form or API input in JavaScript or TypeScript
- Teams that want TypeScript types inferred from a validation schema
- Projects that need async validation, such as checking against a server
- Developers who want to extend schemas with their own custom methods
Not ideal for
- Projects that do not use JavaScript or TypeScript, since the library is written for that ecosystem
- Users who need a non-developer tool with a visual interface
- Projects on the pre-v1 API, since the README points to a separate pre-v1 branch for those docs
How to get it
- 1
Install with a package manager
You'll need: Node.js
Install yup
git clone https://github.com/jquense/yup - 2
Run it
- Import the helpers you need, for example: import { object, string, number } from 'yup';
- Define a schema with object() and its field schemas.
- Call schema.validate(data) with await to check a value and get the parsed result.
- Use schema.cast(data) if you only want type conversion without assertions.
- 3
Get the most out of it
- Use { strict: true } in validate when input is already parsed, to skip parsing overhead
- Use InferType to derive TypeScript types from your schema instead of writing them twice
- Use .when() to create conditional rules that depend on other fields
- Use addMethod to extend built-in schema types with your own methods
- Use .label() and custom messages to make error output clearer for users
Downloads
Strengths
- Concise chained syntax that the README describes as expressive enough for complex, interdependent validations
- Strong TypeScript support, including inferring static types from schemas
- Clear error details and support for custom error messages and localization
Trade-offs
- The README is truncated, so this summary covers only the first part of the API reference
- Its full feature set and edge cases are documented elsewhere and were not visible here
- Pre-v1 users must use a different documentation branch
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| yup (this) | 23.7k | Library | beginner | 6 days ago | Developers validating form or API input in JavaScript or TypeScript |
| zod | 44.2k | Library | beginner | 6 days ago | TypeScript developers who want runtime checks that match their static types |
| ajv | 14.9k | Library | intermediate | 2 months ago | Node.js developers validating API request or response bodies |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.