Customizing Error Messages

I've searched Github & Discord a bit and seen a few mentions of "full error customization", and am finding that I need it, but can't find any examples of it.

I have a type:
const form = type({
   user: {
      email: 'string.email',
      age: 'number>13',
   }
})


When these fields are incorrect, it yields the following error messages:
{
   "user.email": "user.email must be an email address (was \"test\")",
   "user.age": "user.age must be more than 13 (was 12)" 
}


I want to show these outputs in-line in a form. To do that, I need some more customization like:
  • Showing
    email
    instead of user.email (I can use css capitalize to capitalize it if necessary)
  • Getting rid of (was ___)
Right now my best option is to manually manipulate the string to make these changes, which isn't ideal.
Was this page helpful?