UNPKG

io-ts-types

Version:

A collection of codecs and combinators for use with io-ts

28 lines (27 loc) 897 B
/** * @since 0.3.2 */ import * as t from 'io-ts' /** * Changes the output type of the given runtime type * * @example * import * as t from 'io-ts' * import { mapOutput } from 'io-ts-types/lib/mapOutput' * import { optionFromNullable } from 'io-ts-types/lib/optionFromNullable' * import { none, some } from 'fp-ts/lib/Option' * * // Input: t.Type<Option<number>, number | null, t.mixed> * const Input = optionFromNullable(t.number) * * const toUndefined = <A>(x: A | null): A | undefined => (x === null ? undefined : x) * * // Output: t.Type<Option<number>, number | undefined, t.mixed> * const Output = mapOutput(Input, toUndefined) * * assert.strictEqual(Output.encode(none), undefined) * assert.strictEqual(Output.encode(some(1)), 1) * * @since 0.3.2 */ export declare function mapOutput<A, O, I, P>(codec: t.Type<A, O, I>, f: (p: O) => P, name?: string): t.Type<A, P, I>