Decoders
Elegant validation library for type-safe input data for TypeScript
Install / Use
/learn @nvie/DecodersREADME
<img alt="Decoders logo" src="./assets/logo@2x.png" style="width: 100%; max-width: 830px; max-height: 248px" width="830" /><br />
Elegant and battle-tested validation library for type-safe input data for TypeScript.
Basic example
import { array, isoDate, number, object, optional, string } from 'decoders';
// Incoming data at runtime, e.g. the request body
// The point is that this data is untrusted and its type unknown
const externalData = {
id: 123,
name: 'Alison Roberts',
createdAt: '2026-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(isoDate),
tags: array(string),
});
// Call .verify() on the incoming data
const user = userDecoder.verify(externalData);
// ^^^^
// TypeScript will infer this type as:
// {
// id: number;
// name: string;
// createdAt?: Date;
// tags: string[];
// }
Installation
npm install decoders
Requirements
You must set strict: true in your tsconfig.json in order for type inference to work
correctly!
// tsconfig.json
{
"compilerOptions": {
"strict": true
}
}
Documentation
Documentation can be found on decoders.cc.
There is a dedicated page that explains how to build your own decoders.
Related Skills
node-connect
337.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
83.2kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
review-duplication
99.2kUse this skill during code reviews to proactively investigate the codebase for duplicated functionality, reinvented wheels, or failure to reuse existing project best practices and shared utilities.
