November 2019
Beginner
804 pages
20h 1m
English
io-ts (https://github.com/gcanti/io-ts) is a library that can be used to define runtime types. Those runtime types will allow us to perform stricter type checks at runtime.
The io-ts library defines a Type class. We will use instances of that class as validators. At runtime, they'll be used to strictly validate that objects have the shape and types that we expect. That way, we will be able to use them safely.
Instances of the Type class can be created using utility functions provided by io-ts. Here's a basic example that creates and uses a string validator:
import * as t from "io-ts";
const nameValidator = t.string;
const validationResult = nameValidator.decode('foobar');
validationResult.isRight(); // true
In this example, we've created ...
Read now
Unlock full access