Skip to content
On this page

Farfetched and Valibot

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

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

valibotContract

Creates a Contract based on given BaseSchema.

ts
import { object, literal, number } from 'valibot';
import { valibotContract } from '@farfetched/valibot';

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

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