Skip to content

mmmurray/convince

Repository files navigation

Convince

Type safe schema validation library. Lightweight alternative to Zod.

Install

yarn add convince

Or

npm i convince

Usage

import { s, SchemaType } from 'convince';

const thingSchema = s.object({
  foo: s.string(),
  bar: s.number().optional(),
  baz: s.boolean(),
});

type Thing = SchemaType<typeof thingSchema>;

const thingResult = thingSchema.parse({
  foo: 'Hello',
  baz: true,
});

if (thingResult.ok) {
  console.log(thingResult.data.foo);
}