Skip to content
On this page

Farfetched and superstruct

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

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

superstructContract

Creates a Contract based on given Struct.

ts
import * as s from 'superstruct';
import { superstructContract } from '@farfetched/superstruct';

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

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