gillchristian/io-ts-reporters

Is it possible to report Either<DecodeError, A>

aldex32 opened this issue · 1 comments

Hello,
I am using io-ts@2.2.16 and io-ts-reporters@2.0.1, 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.