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 type Hope 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
-
Hi,
it seems that the suggested approach to handle custom errors is to use SetErrorFunction and look for the presence of a
errorMessage
property in the schema params like this:And then define
errorMessage
as part of the schema options like so:But
errorMessage
is an unknown property to SchemaOptions, it will happily accept things likeerrorMessagez
and then fallback to the default messages.How can we make using a custom
errorMessage
property more maintainable? How have other users solved this?errorMessage
is not present and build tests around it?errorMessage
property?Or am I missing something?
Beta Was this translation helpful? Give feedback.
All reactions