Skip to content

How to make client-side validation with default values? #275

Answered by sinclairzx81
whalemare asked this question in Q&A
Discussion options

You must be logged in to vote

@whalemare Hi, I have actually just pushed a patch / fix for this on @sinclair/typebox@0.25.3 so information below relates to this version (and above)

Validation & Default Values

TypeBox doesn't provide functionality to create default values during validation (either the data is correct or it's not). But if you are using Ajv, you can use useDefaults to automatically set default values if certain properties happen to be missing. This will need to be configured on the AJV object. Refer to the Ajv documentation for more information.

Value.Create() & Value.Cast()

As noted, while TypeBox doesn't provide a mechanism to automatically create default values for schemas specifically on validate, it…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by whalemare
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants