UNPKG

806 BTypeScriptView Raw
1/**
2 * @since 0.5.0
3 */
4import * as t from 'io-ts'
5/**
6 * Returns a clone of the given codec that replace a nullable input with the given value `a`
7 *
8 * @example
9 * import { fromNullable } from 'io-ts-types/lib/fromNullable'
10 * import * as t from 'io-ts'
11 * import { right } from 'fp-ts/lib/Either'
12 * import { PathReporter } from 'io-ts/lib/PathReporter'
13 *
14 * const T = fromNullable(t.number, -1)
15 *
16 * assert.deepStrictEqual(T.decode(1), right(1))
17 * assert.deepStrictEqual(T.decode(null), right(-1))
18 * assert.deepStrictEqual(T.decode(undefined), right(-1))
19 * assert.deepStrictEqual(PathReporter.report(T.decode('a')), ['Invalid value "a" supplied to : fromNullable(number)'])
20 *
21 * @since 0.5.0
22 */
23export declare function fromNullable<C extends t.Mixed>(codec: C, a: t.TypeOf<C>, name?: string): C
24
\No newline at end of file