explaingit

jquense/yup

📈 Trending23,681TypeScriptAudience · developerComplexity · 2/5ActiveLicenseSetup · easy

TLDR

A JavaScript/TypeScript library for validating that user input and API data match expected rules before you use it, with automatic type generation.

Mindmap

mindmap
  root((repo))
    What it does
      Validates user input
      Checks API responses
      Coerces data types
      Generates TypeScript types
    How it works
      Define schema rules
      Chain descriptors
      Check incoming data
      Return errors or clean data
    Use cases
      Form validation
      API response checking
      Config file validation
      Database constraints
    Tech stack
      JavaScript
      TypeScript
      Formik integration
      React Hook Form
    Key features
      Async validation
      Auto type generation
      Clear error messages
      Data coercion

Things people build with this

USE CASE 1

Validate form submissions before sending to a server, catching missing or malformed fields early.

USE CASE 2

Check API responses match expected structure before your code tries to use them.

USE CASE 3

Automatically convert string form inputs (like "24") into the correct types (number 24) your app expects.

USE CASE 4

Validate configuration files or user-provided JSON to ensure required fields and correct data types.

Tech stack

JavaScriptTypeScriptNode.js

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

In plain English

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.

Copy-paste prompts

Prompt 1
Show me how to set up a Yup schema to validate a user registration form with email, password, and age fields.
Prompt 2
How do I use Yup with React Hook Form to validate a form and display error messages next to each field?
Prompt 3
Write a Yup schema that validates an API response object and automatically generates TypeScript types from it.
Prompt 4
How can I add async validation to a Yup schema to check if an email address is already registered in my database?
Prompt 5
Create a Yup schema that coerces a string input into a number and validates it's between 1 and 100.
Open on GitHub → Explain another repo

Generated 2026-05-18 · Model: sonnet-4-6 · Verify against the repo before relying on details.