Skip to content

RFC Custom error messages for TypeBox #805

@tinkermakar

Description

@tinkermakar

This is rather a Request for Comments for a feature I want to PR. I wonder if I should name the new TypeBox field message, errorMessage or something else. I am going to open the PR once there is feetback from maintainers.

Is your feature request related to a problem? Please describe.

There is no way to add custom error messages to the TypeBox resolver. E.g. my use case is a consent checkbox and rather than getting userConsent must be true for a consent checkbox I would need to display a user-friendly message like Your consent is required, but I can't. Alternatives like Zod and Yup have an easy message property for such cases, but TypeBox doesn't have one

Describe the solution you'd like

  1. Reference a new field on TypeBox schemas that will hold the message. TypeBox itself throws no errors for additional fields, so it can be anything: message, errorMessage etc. I wan to go with message, but I would highly appreciate if you would comment on that.

  2. Modify resolver to read that new field, something along those lines: Custom errors using TypeCompiler sinclairzx81/typebox#500 (comment)

Describe alternatives you've considered
No good alternatives other than switching to Zod

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions