Search


Search something to see results

fromGuard

Utility to create schemas.
Used to create most of the primitives.
Can be used to create custom schemas like Email.

Type Parameters

  • T
  • Input = unknown

Parameters

  • name: string
  • guard: Guard<Input, T>

Returns Schema<T, Input>

import { x } from 'unhoax'

const string = x.fromGuard(
'string',
(input) => typeof input === 'string'
)

// creating an email type:
type Email = string & { _tag: 'Email' }
declare const isEmail: (input: unknown) => input is Email

const email = x.fromGuard('Email', isEmail)