Search


Search something to see results

recover

Allows to never fail from parsing an input by providing a fallback.

Type Parameters

  • U

Parameters

  • getFallback: Object

Returns Object

fallback for usage without callback

import * as x from 'unhoax'

const orString = x.recover(() => 'not a number')
const schema = orString(x.number)

// or, using pipe
import pipe from 'just-pipe'

const schema = pipe(x.number, x.recover(() => 'not a number'))

schema.parse(42) // { success: true, value: 42 }
schema.parse('toto') // { success: true, value: 'not a number' }