-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better validation errors for tagged unions #350
Comments
I can't repro with import * as t from 'io-ts'
import { PathReporter } from 'io-ts/lib/PathReporter'
const C = t.union([
t.type({
type: t.literal('A'),
foo: t.number
}),
t.type({
type: t.literal('B'),
bar: t.number
})
])
console.log(PathReporter.report(C.decode({ type: 'B', bar: 'wrong type' })))
// [ 'Invalid value "wrong type" supplied to : ({ type: "A", foo: number } | { type: "B", bar: number })/1: { type: "B", bar: number }/bar: number' ] |
Oh I see, my bad. |
Alright, I'll reopen this so that this can be thought about. The only difference is
|
In case someone would find it useful, I implemented a more aggressive union reduction reporter: https://github.com/klesun/io-ts-better-union-error-reporter The built-in |
🚀 Feature request
Current Behavior
Desired Behavior
It would be great if there was a way to reduce validation errors if there's a tag match. I have a tagged union of 10 codecs with dozens of properties and it is very hard to understand what is actually wrong.
So with above example codec, I'd expect the following validation error:
The text was updated successfully, but these errors were encountered: