Replies: 1 comment 1 reply
-
|
@matjaeck Hi,
Unfortunately, there's not really an elegant way to solve for misspelt properties (this is because SchemaOptions is an open ended interface type that can be assigned any additional properties). It is however possible to use interface/module augmentation to add additional known properties to the TB option interfaces. This will give auto-complete for additional "known" properties as well as static checking. import { Type, Static } from '@sinclair/typebox'
// It is possible to augument TB interfaces in the following way such that you get
// auto-complete and static checking for additional 'known' properties, but it is
// not possible (afaik) check for additional 'unknown' properties..
declare module '@sinclair/typebox' {
export interface SchemaOptions {
errorMessage?: string
}
}
Type.String({ errorMessage: false }) // known property & wrong type
Type.String({ errorMessage: 'oh no' }) // known property & correct type
Type.String({ errorMessagz: 'oh no' }) // unknown property & unknown typeHope this helps |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
it seems that the suggested approach to handle custom errors is to use SetErrorFunction and look for the presence of a
errorMessageproperty in the schema params like this:And then define
errorMessageas part of the schema options like so:But
errorMessageis an unknown property to SchemaOptions, it will happily accept things likeerrorMessagezand then fallback to the default messages.How can we make using a custom
errorMessageproperty more maintainable? How have other users solved this?errorMessageis not present and build tests around it?errorMessageproperty?Or am I missing something?
Beta Was this translation helpful? Give feedback.
All reactions