Search


Search something to see results

fromPredicate

Utility to create schemas.
Can be used to create custom schemas like Email.

Type Parameters

  • T
  • Input = unknown

Parameters

  • name: string
  • predicate: Predicate<Input, T>

Returns Schema<T, Input>

import * as x from 'unhoax'

const string = x.fromPredicate(
'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.fromPredicate('Email', isEmail)