io-ts
io-ts is a runtime type system for TypeScript that bridges the gap between compile-time types and runtime validation using functional programming concepts from …
Installation
npm install io-ts fp-ts
yarn add io-ts fp-ts
pnpm add io-ts fp-ts
Import
import * as t from 'io-ts';
Quick Example
import * as t from 'io-ts';
import { isRight } from 'fp-ts/Either';
const User = t.type({
name: t.string,
email: t.string,
age: t.union([t.number, t.undefined]),
});
type User = t.TypeOf<typeof User>;
const result = User.decode({ name: 'Alice', email: '[email protected]' });
if (isRight(result)) console.log(result.right);About io-ts
io-ts is a runtime type system for TypeScript that bridges the gap between compile-time types and runtime validation using functional programming concepts from the fp-ts library. io-ts codecs define both the runtime validator and the TypeScript type in a single declaration — t.type({ name: t.string, age: t.number }) creates a codec that validates unknown data at runtime and infers the TypeScript type { name: string; age: number } statically. The library uses the concept of codecs that can both decode (validate/parse incoming data) and encode (serialize outgoing data), making it suitable for API boundaries where data needs to be validated in both directions. io-ts supports primitive types, objects, arrays, intersections, unions, partial types, readonly types, branded types (nominal types with runtime validation), and recursive types. The decode method returns an Either type from fp-ts (Left for errors, Right for valid data), encouraging explicit error handling. io-ts is particularly popular in codebases that already use fp-ts for functional programming patterns. While Zod has become more popular for general use due to its simpler API, io-ts provides superior integration with the fp-ts ecosystem and functional programming patterns.
Quick Facts
| Package | io-ts |
| Category | Validation |
| Weekly Downloads | 1M+ |
| License | MIT |
| Install | npm install io-ts fp-ts |
Related Packages
Zod is a TypeScript-first schema validation library that provides a concise, chainable API for defin…
Runtypes is a runtime validation library for TypeScript that provides a simple, composable API for d…
Superstruct is a library for validating data in JavaScript and TypeScript using composable, predicta…
Ajv (Another JSON Schema Validator) is the fastest JSON Schema validator for JavaScript and TypeScri…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.