Replies: 1 comment 7 replies
-
Is this what you are looking for? const SuccessCode = z.number().min( 1000 ).max( 1999 )
const ClientErrorCode = z.number().min( 2000 ).max( 2999 )
const ServerErrorCode = z.number().min( 3000 ).max( 3999 )
const StatusCode = z.union( [
ServerErrorCode,
ClientErrorCode,
SuccessCode,
] )
const input = 4000
const result = StatusCode.safeParse( input )
!result.success && console.log( result.error.issues )
// [
// {
// code: "too_big",
// maximum: 3999,
// type: "number",
// inclusive: true,
// exact: false,
// message: "Number must be less than or equal to 3999",
// path: []
// }
// ] If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏 |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Issue: Zod error message for unions is misleading
Zod error I got is
The valid error object should be this instead
The validation works but the error is misleading.
I tried creating a custom error by using
errorMap
but it still returned the above errorBeta Was this translation helpful? Give feedback.
All reactions