Skip to content
On this page

Farfetched and io-ts

Integration is distributed as a separate package, you have to install it and its peer dependencies before usage

sh
pnpm install io-ts fp-ts @farfetched/io-ts
sh
yarn add io-ts fp-ts @farfetched/io-ts
sh
npm install io-ts fp-ts @farfetched/io-ts

ioTsContract

Creates a Contract based on given Type.

ts
import * as t from 'io-ts';
import { ioTsContract } from '@farfetched/io-ts';

const Asteroid = t.type({
  type: t.literal('asteroid'),
  mass: t.number,
});

const asteroidContract = ioTsContract(Asteroid);

/* typeof asteroidContract === Contract<
 *   unknown, 👈 it accepts something unknown
 *   { type: 'asteriod', mass: number }, 👈 and validates if it is an asteroid
 * >
 */

Released under the MIT License.