Link Search Menu Expand Document

index overview

An io-ts Reporter.

Example

import * as t from 'io-ts'
import Reporter from 'io-ts-reporters'

const User = t.interface({name: t.string})

assert.deepEqual(Reporter.report(User.decode({nam: 'Jane'})), [
  'Expecting string at name but instead got: undefined',
])
assert.deepEqual(Reporter.report(User.decode({name: 'Jane'})), [])

Added in v1.2.0


Table of contents


deprecated

reporter

Deprecated, use the default export instead.

Signature

export declare const reporter: <T>(
  validation: E.Either<t.Errors, T>,
  options?: ReporterOptions | undefined,
) => string[]

Added in v1.0.0

formatters

ReporterOptions (interface)

Signature

export interface ReporterOptions {
  truncateLongTypes?: boolean
}

Added in v1.2.2

formatValidationError

Format a single validation error.

Signature

export declare const formatValidationError: (
  error: t.ValidationError,
  options?: ReporterOptions | undefined,
) => O.Option<string>

Added in v1.0.0

formatValidationErrors

Format validation errors (t.Errors).

Signature

export declare const formatValidationErrors: (
  errors: t.Errors,
  options?: ReporterOptions | undefined,
) => string[]

Example

import * as E from 'fp-ts/Either'
import * as t from 'io-ts'
import {formatValidationErrors} from 'io-ts-reporters'

const result = t.string.decode(123)

assert.deepEqual(
  E.mapLeft(formatValidationErrors)(result),
  E.left(['Expecting string but instead got: 123']),
)

Added in v1.2.0

internals

TYPE_MAX_LEN

Signature

export declare const TYPE_MAX_LEN: 160

Added in v1.2.1