UNPKG

739 BTypeScriptView Raw
1/**
2 * @since 0.4.3
3 */
4import * as t from 'io-ts'
5/**
6 * Returns a clone of the given codec which uses the given `validate` function
7 *
8 * @example
9 * import { withValidate } from 'io-ts-types/lib/withValidate'
10 * import * as t from 'io-ts'
11 * import { PathReporter } from 'io-ts/lib/PathReporter'
12 * import { either, right } from 'fp-ts/lib/Either'
13 *
14 * const T = withValidate(t.number, (u, c) => either.map(t.number.validate(u, c), n => n * 2))
15 *
16 * assert.deepStrictEqual(T.decode(1), right(2))
17 * assert.deepStrictEqual(PathReporter.report(T.decode(null)), ['Invalid value null supplied to : number'])
18 *
19 * @since 0.4.3
20 */
21export declare function withValidate<C extends t.Any>(codec: C, validate: C['validate'], name?: string): C
22
\No newline at end of file