-
Notifications
You must be signed in to change notification settings - Fork 90
Closed
Labels
Milestone
Description
I recently received a confusing error message from union validation. Take the following as an example... a simple union of 2 objects:
import * as t from 'runtypes'
const S = t.String.withConstraint((x) => x === 'bar' || 'Should be bar')
const R = t.Record({ s: S }).Or(t.Record({ t: S }))
try {
R.check({ s: 'rab' })
} catch (error) {
console.error(error)
}This produces:
ValidationError: Expected { s: string; } | { t: string; }, but was object
at ...
<stack traces>
at ... {
code: 'TYPE_INCORRECT'
}
The message Expected { s: string; } | { t: string; }, but was object isn't all that helpful. Can this message be improved somehow?
Reactions are currently unavailable