Skip to content
On this page

Farfetched and typed-contracts

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

sh
pnpm install typed-contracts @farfetched/typed-contracts
sh
yarn add typed-contracts @farfetched/typed-contracts
sh
npm install typed-contracts @farfetched/typed-contracts

typedContract

Creates a Contract based on given Contract from typed-contracts.

ts
import { literal, object, number } from 'typed-contracts';
import { typedContract } from '@farfetched/typed-contracts';

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

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