2.0.1 • Published 3 years ago

io-ts-reporters v2.0.1

Weekly downloads
115,704
License
MIT
Repository
github
Last release
3 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-botverdad@dotrun/gae-js-core@cambrianone/camb-clientio-ts-routerio-ts-api-clientio-ts-koa-middlewareicf-room-client-usertypescript-typetreeqlite-http-servertreeqlite-kysely-dialect@ahryman40k/typescript-over-asymmetrik@balena/compose@balena/multibuild@baqhub/sdk@agiledigital/jiralint-lib@3wks/gae-node-nestjs@cruhl/hueyesno-http@forge/runtime@fengcart/common@fengcart/http@futureverse/react@futureverse/sylo-protocol-sdk@futureverse/experience-sdk@infinitebrahmanuniverse/nolb-io-@kozmoai/backstage-plugin-argo-cd@kmudrick/io-ts-openapi@lsge/pgtyped-cli@ithaca/mq@macrof/shared@mhoc/mongodb-atlas@mhoc/synthesize@mhoc/workers-io@niciusb/amazon-advertising-api-sdk@nll/api-codegen-ts@faia/cli@model-ts/core@model-ts/dynamodb@mondomob/gae-node-nestjs@mondomob/gae-node-nestjs-bak@monaxlabs/aspen-sdk@monaxlabs/cambium@monaxlabs/gen@monaxlabs/phloem@imgix/gatsby-source-url@imtbl/imx-link-lib@imtbl/imx-sdk@holochain/try-o-rama@qdev/utils-ts@sanity-ts/fetcher@scaleleap/amazon-advertising-api-sdk@schemafire/core@pgtyped-curly/cli@pgtyped-pydantic/cli@pgtyped/cli@sepezho/lib@roadiehq/backstage-plugin-argo-cdmongo-iots-wrappermhcmson-prem-connectrc.tsprocess-env-tsreact-fetchablepgtyped-cli-2pgtyped-rescriptphp-importspolypayresin-multibuildresources-ioimx-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-apiaxdcore-common-tscsgo-gamestate-clientdecode-tsdecodesapsso2bls-wallet-aggregator-proxydocs-ts-extraeli-video-interview-reportexpress-fpfp-express-validationfp-ts-httpgae-node-nestjs-kosta
2.0.1

3 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

7 years ago

0.0.19

7 years ago

0.0.18

7 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

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago