Validation1M+/wkMIT

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
npm install io-ts fp-ts
yarn
yarn add io-ts fp-ts
pnpm
pnpm add io-ts fp-ts

Import

ESM
import * as t from 'io-ts';

Quick Example

usage
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

Packageio-ts
CategoryValidation
Weekly Downloads1M+
LicenseMIT
Installnpm install io-ts fp-ts

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.