Skip to main content Link Menu Expand (external link) Document Search Copy Copied

withMessage overview

Added in v0.4.3


Table of contents


withMessage

Returns a clone of the given codec that sets the given string as error messsage

Signature

export function withMessage<C extends t.Any>(codec: C, message: (i: t.InputOf<C>, c: t.Context) => string): C { ... }

Example

import { withMessage } from 'io-ts-types/lib/withMessage'
import * as t from 'io-ts'
import { PathReporter } from 'io-ts/lib/PathReporter'
import { right } from 'fp-ts/lib/Either'

const T = withMessage(t.number, () => 'Invalid number')

assert.deepStrictEqual(T.decode(1), right(1))
assert.deepStrictEqual(PathReporter.report(T.decode(null)), ['Invalid number'])

Added in v0.4.3