io-ts-reporters
io-ts-reporters copied to clipboard
Is it possible to report Either<DecodeError, A>
Hello,
I am using [email protected]
and [email protected]
, but I cannot report an error for decode responses such as Either<DecodeError, A>
. This is an example where I want to use the report instead of a raw error.
import * as D from 'io-ts/Decoder';
import { pipe } from 'fp-ts/function';
import { fold } from 'fp-ts/Either';
export function decode<A>(input: unknown, decoder: D.Decoder<unknown, A>): A {
return pipe(
decoder.decode(input),
fold(
(errors) => {
throw new Error(JSON.stringify(errors)); // Here I want to use the reporter.
},
(value: A) => value,
),
);
}
Are you planning to support the D.DecodeError
for reporting?
Hi, I hadn't used io-ts/Decoder
yet, only io-ts/index
, so I did not come across the problem. And yes, this should be supported.