Skip to content
On this page

Farfetched and Runtypes

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

sh
pnpm install runtypes @farfetched/runtypes
sh
yarn add runtypes @farfetched/runtypes
sh
npm install runtypes @farfetched/runtypes

Showcases

runtypeContract

Creates a Contract based on given Runtype.

ts
import { Record, Literal, Number, Vector } from 'runtypes';
import { runtypeContract } from '@farfetched/runtypes';

const Asteroid = Record({
  type: Literal('asteroid'),
  mass: Number,
});

const asteroidContract = runtypeContract(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.