yup
Dead simple Object schema validation
A JavaScript and TypeScript library for describing what valid data looks like as a schema, then checking incoming form or API data against those rules and returning clear, field-specific error messages when something fails.
Yup is a JavaScript/TypeScript library that solves a very common problem in web development: validating that user input or data from an API actually matches what you expect before you use it. For example, you might expect a form field to contain a valid email address and a positive number for age — Yup lets you describe those rules as a schema (a blueprint of what valid data looks like), then check incoming data against that blueprint.
You define a schema by chaining together descriptive rules — things like "this field is required," "this must be a positive integer," or "this must be a valid URL." When data comes in, Yup either validates it and returns clean, correctly-typed values, or gives back clear error messages explaining exactly what failed.
Beyond just checking rules, Yup also coerces data — it can automatically convert a string like "24" into the number 24, which is useful when dealing with form inputs that always come back as strings.
Yup works well with TypeScript, so it can generate type definitions automatically from your schema, reducing repetitive type declarations. It supports async validation (for cases like checking whether an email already exists in a database) and is a popular companion to form libraries like Formik and React Hook Form.
Use it whenever you need to reliably validate structured data from forms, APIs, or configuration files in a JavaScript or TypeScript project.
Where it fits
- Validate a user signup form's email, password, and age fields with specific error messages for each failure
- Auto-generate TypeScript types from your validation schema so you don't write the same type definitions twice
- Validate and coerce API response data to catch unexpected formats before they cause bugs in your app