A
arktype2mo ago
Rick

Passing a name for a primitive value?

Is there a way to pass a name to a primitive value being checked, so that in the error message you get shown "(name) must be..." like for object properties?
1 Reply
Rick
RickOP2mo ago
Currently I am using this little helper to do it:
export function namedType(schema: Type, name: string) {
return schema.configure({
message: (ctx) => `${name} ${ctx.problem}`,
});
}
export function namedType(schema: Type, name: string) {
return schema.configure({
message: (ctx) => `${name} ${ctx.problem}`,
});
}
But I wondered if there is a native api to do this that I missed?

Did you find this page helpful?