Closed aleclarson closed 6 months ago
Oh, what do ya know... it is already! Just use error.error
to access it.
I guess the only issue is that it's not exposed to TypeScript anywhere.
Here's a little hack I'm using (warning: potentially fragile):
import {
TransformDecodeCheckError,
TransformEncodeCheckError,
} from '@sinclair/typebox/build/require/value'
export const isTypeError = (
error: any
): error is TransformEncodeCheckError | TransformDecodeCheckError =>
error.constructor.name.endsWith('CheckError')
// Example
if (isTypeError(e)) {
console.log(e.error) // ✔️
}
When an error is thrown by
Value.Encode
orValue.Decode
, theTypeBoxError
should have the validation issues attached to it.