gcanti / io-ts-types

A collection of codecs and combinators for use with io-ts
https://gcanti.github.io/io-ts-types/
MIT License
311 stars 40 forks source link

withMessage helper does not work as expected #95

Closed karthikiyengar closed 5 years ago

karthikiyengar commented 5 years ago

Versions:

"io-ts": "^1.8.5",
"io-ts-types": "^0.4.6",

Minimal reproduction:

import { withMessage } from "io-ts-types/lib/withMessage";
import * as t from "io-ts";
import { PathReporter } from "io-ts/lib/PathReporter";

const T = withMessage(t.number, () => "Invalid number!");

const decoded = T.decode(null);
console.log(PathReporter.report(decoded));
//=> [ 'Invalid value null supplied to : number' ]

Looks like the message property is not being set correctly - reports as undefined

karthikiyengar commented 5 years ago

Did a bit of digging around, looks like this works.

const decoded = T.validate(null, t.getDefaultContext(T))
console.log(PathReporter.report(decoded))

Looks like issues with passing the context to decode?

gcanti commented 5 years ago

@karthikiyengar weird, your repro is literally the test I wrote here

gcanti commented 5 years ago

Wait... I just updated my local version to io-ts@1.8.5 and I can see the issue now. Let me investigate...

gcanti commented 5 years ago

@karthikiyengar just released a patch

karthikiyengar commented 5 years ago

Thanks a lot @gcanti, that was incredibly quick :-)

gcanti commented 5 years ago

Thanks to you for the bug report