gitmyhub

io-ts

TypeScript ★ 6.8k updated 1y ago

Runtime type system for IO decoding/encoding

io-ts is a TypeScript library that lets you validate data at the moment your program receives it, not just while writing the code. TypeScript adds type annotations to JavaScript, but those checks only happen during development and disappear when the code actually runs. When your program fetches data from an API or reads a file, TypeScript has no way to confirm that what arrived matches what you expected. io-ts solves that gap by letting you define types that can actively inspect and validate real data at runtime.

When validation passes, io-ts can decode the raw data into a typed value your program can use safely. When it fails, it returns a description of what went wrong rather than throwing a vague error. This makes it easier to trace exactly which field or value did not match the expected shape.

The library has a required peer dependency called fp-ts, which is another library by the same author that brings functional programming patterns to TypeScript. You install both together. Functional programming here means that operations like decoding return explicit success or failure values rather than relying on exceptions, which makes error handling more predictable.

The README is brief and mostly points to separate documentation files for specific modules. The stable API is documented in an index file. There is also a set of experimental modules introduced in version 2.2, covering Decoder, Encoder, Codec, Eq, and Schema functionality. These experimental modules are flagged as independent from the stable API and may change without notice.

The README does not include worked examples or a getting-started walkthrough. It is a short pointer document aimed at developers who already know what runtime type validation is and are looking for installation steps and module references.