Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time
December 2, 2021 11:34
January 5, 2022 20:31
December 2, 2021 11:34
January 4, 2022 11:01
October 4, 2017 21:40
February 8, 2022 14:58
July 4, 2023 09:47
December 4, 2023 15:40
December 4, 2023 15:39
December 19, 2021 09:44

Decoders logo

npm Build Status Coverage Status Minified Size

Elegant and battle-tested validation library for type-safe input data for TypeScript and Flow.


Data entering your application from the outside world should not be trusted without validation and often is of the any type, effectively disabling your type checker around input values. It's an industry good practice to validate your expectations right at your program's boundaries. This has two benefits: (1) your inputs are getting validated, and (2) you can now statically know for sure the shape of the incoming data. Decoders help solve both of these problems at once.


import { array, iso8601, number, object, optional, string } from 'decoders';

// Incoming data at runtime
const externalData = {
    id: 123,
    name: 'Alison Roberts',
    createdAt: '1994-01-11T12:26:37.024Z',
    tags: ['foo', 'bar'],

// Write the decoder (= what you expect the data to look like)
const userDecoder = object({
    id: number,
    name: string,
    createdAt: optional(iso8601),
    tags: array(string),

// Call .verify() on the incoming data
const user = userDecoder.verify(externalData);
//    ^^^^
//    TypeScript can automatically infer this type now:
//    {
//      id: number;
//      name: string;
//      createdAt?: Date;
//      tags: string[];
//    }


Documentation can be found on

Building your own decoders

There is a dedicated page in the docs that explains how to build your own decoders — it’s fun!