2.0.1 • Published 4 years ago

io-ts-reporters v2.0.1

Weekly downloads
115,704
License
MIT
Repository
github
Last release
4 years ago

io-ts-reporters

Error reporters for io-ts.

scarf-downloads

Currently this package only includes one reporter. The output is an array of strings in the format of:

Expecting ${expectedType} at ${path} but instead got: ${actualValue}

And for union types:

Expecting one of:
    ${unionType1}
    ${unionType2}
    ${...}
    ${unionTypeN}
at ${path} but instead got: ${actualValue}

Installation

yarn add io-ts-reporters

Example

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

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

// When decoding fails, the errors are reported
reporter.report(User.decode({nam: 'Jane'}))
//=> ['Expecting string at name but instead got: undefined']

// Nothing gets reported on success
reporter.report(User.decode({name: 'Jane'}))
//=> []

To only format the validation errors in case the validation failed (ie. mapLeft) use formatValidationErrors instead.

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

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

const result = User.decode({nam: 'Jane'}) // Either<t.Errors, User>

E.mapLeft(formatValidationErrors)(result) // Either<string[], User>

For more examples see the tests.

TypeScript compatibility

io-ts-reporters versionrequired typescript version
1.0.03.5+
<= 0.0.212.7+

Testing

yarn
yarn run test

Credits

This library was created by OliverJAsh.

@turtleside/octopus@everything-registry/sub-chunk-1924@imtbl/imxd-clientimx-sdkworkativ-assistant-on-prem-agentworkativ-automate-on-prem-connectvk-chat-botverdadio-ts-routerio-ts-api-clientio-ts-koa-middlewareimx-sdk-alterinspectpackmarlowe-ts-sdk-betamedia-inspectorsolarjs@xgen-helix/backstage-plugin-argo-cd@trayio/commons@userlike/settler@zalastax/nolb-io-@zagrajmy/app@tegro/ton3-clientabap-adt-apiaxd@paima/pgtyped-cli@pgtyped-curly/cli@pgtyped-lite/cli@pgtyped-pydantic/cli@pgtyped/clifp-express-validationfp-ts-httpgae-node-nestjs-kosta@step2yeung/inspectpack@sylo/io-tsdocs-ts-extraeli-video-interview-reportexpress-fp@3wks/gae-node-nestjs@cambrianone/camb-client@cambrianone/spec@cambrianone/utils@bsw-front/configuration@baqhub/sdk@balena/compose@balena/multibuildcore-common-tscsgo-gamestate-clientdecode-tsdecodesapsso2bls-wallet-aggregator-proxy@agiledigital/jiralint-lib@ahryman40k/typescript-over-asymmetrikicf-room-client-usertypescript-typetreeqlite-http-servertreeqlite-kysely-dialectyesno-http@infinitebrahmanuniverse/nolb-io-mongo-iots-wrappermhcmson-prem-connectrc.tsprocess-env-tsreact-fetchablepgtyped-cli-2pgtyped-rescriptphp-importspolypayresin-multibuildresources-io@cruhl/hue@dotrun/gae-js-core@fengcart/http@fengcart/common@faia/cli@forge/runtime@skeema/core@skitter/file-utils@holochain/try-o-rama@slicemachine/manager@slicemachine/plugin-kit@slicemachine/core@imtbl/imx-sdk@imtbl/imx-link-lib@imgix/gatsby-source-url@roadiehq/backstage-plugin-argo-cd@mhoc/mongodb-atlas@mhoc/synthesize@mhoc/workers-io@futureverse/experience-sdk@futureverse/react@futureverse/sylo-protocol-sdk@sanity-ts/fetcher@ithaca/mq@model-ts/core@model-ts/dynamodb@mondomob/gae-node-nestjs@mondomob/gae-node-nestjs-bak@monaxlabs/aspen-sdk@monaxlabs/cambium
2.0.1

4 years ago

2.0.0-rc1

4 years ago

2.0.0

4 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

6 years ago

0.0.21

7 years ago

0.0.20

8 years ago

0.0.19

8 years ago

0.0.18

8 years ago

0.0.17

8 years ago

0.0.16

8 years ago

0.0.15

8 years ago

0.0.14

8 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago