customizing error messages

Hi, I'm just trying this library and so far looks very promising. I cannot, however, find anywhere if it is possible to have different error messages for different validators (for a single field)? For example in Zod I could do sth like this: z.array().min(2, 'choose at least 2').max(3, 'choose no more than 3') Is there an equivalent in ArkType?
3 Replies
ssalbdivad
ssalbdivad2mo ago
Hey glad you're enjoying it! This would be the easiest way:
const strings = type("string[]")
.atLeastLength({
rule: 2,
"meta.message": "choose at least 2"
})
.atMostLength({
rule: 3,
"meta.message": "choose no more than 3"
})
const strings = type("string[]")
.atLeastLength({
rule: 2,
"meta.message": "choose at least 2"
})
.atMostLength({
rule: 3,
"meta.message": "choose no more than 3"
})
dominikcz
dominikczOP2mo ago
nice, thank you
TaQuanMinhLong
@ssalbdivad I think the docs for making custom error message is currently not really clear there are cases where I need to display error messages base on the current locale (language) of the user, how can we achieve this?

Did you find this page helpful?