2.0.1 • Published 2 years ago

io-ts-reporters v2.0.1

Weekly downloads
115,704
License
MIT
Repository
github
Last release
2 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-sdk@ahryman40k/typescript-over-asymmetrik@3wks/gae-node-nestjsabap-adt-api@sepezho/lib@skeema/core@sylo/io-ts@nll/api-codegen-ts@agiledigital/jiralint-lib@zalastax/nolb-io-@balena/multibuildinspectpack@baqhub/sdk@balena/composeio-ts-api-clientio-ts-koa-middlewareio-ts-routerironsource-mediation@cruhl/huemedia-inspectordecode-tsmhcmson-prem-connectaxios-io-tsaxdimx-sdk-altermongo-iots-wrappercsgo-gamestate-clientmarlowe-ts-sdk-betaprocess-env-tspgtyped-cli-2pgtyped-rescriptphp-importsdocs-ts-extrapolypaytreeqlite-http-servertreeqlite-kysely-dialectworkativ-assistant-on-prem-agentworkativ-automate-on-prem-connectyesno-httptypescript-typeverdadvk-chat-bot@qdev/utils-ts@roadiehq/backstage-plugin-argo-cd@sanity-ts/fetcher@trayio/commons@scaleleap/amazon-advertising-api-sdk@skitter/file-utils@slicemachine/core@slicemachine/manager@slicemachine/plugin-kit@schemafire/core@step2yeung/inspectpack@userlike/settler@tegro/ton3-client@zagrajmy/app@monaxlabs/aspen-sdk@monaxlabs/cambium@monaxlabs/gen@monaxlabs/phloem@pgtyped-pydantic/cli@pgtyped/cli@niciusb/amazon-advertising-api-sdk@mondomob/gae-node-nestjs@mondomob/gae-node-nestjs-bakbls-wallet-aggregator-proxy@holochain/try-o-rama@dotrun/gae-js-corecore-common-tsexpress-fp@infinitebrahmanuniverse/nolb-io-@forge/runtime@futureverse/experience-sdk@futureverse/react@futureverse/sylo-protocol-sdkeli-video-interview-reportresources-ioresin-multibuildrc.tsreact-fetchable@faia/cli@imtbl/imx-link-lib@imtbl/imx-sdk@imgix/gatsby-source-url@ithaca/mqsolarjsfp-ts-httpfp-express-validation@kmudrick/io-ts-openapigae-node-nestjs-kosta@kozmoai/backstage-plugin-argo-cd@lsge/pgtyped-cli@macrof/shared@mhoc/mongodb-atlas@mhoc/synthesize@mhoc/workers-io
2.0.1

2 years ago

2.0.0-rc1

3 years ago

2.0.0

3 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

5 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago