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
- Real-world showcase with SolidJS around JSON API
- Real-world showcase with React around JSON API
- Real-world showcase with Forest around JSON API
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
* >
*/