You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Good question! I'm working on the docs for v2 now but error messages are very customizable!
Here are a few options for this situation:
import{type}from"arktype"exportconstproject=type({name: ["string","@","a string 👽"]})constout=project({name: 5})if(outinstanceoftype.errors){// 'name must be a string 👽 (was number)'console.log(out.summary)}else{console.log(`Hi, ${out.name}!`)}constname=type("string").describe("a string 👽")// this is equivalent to aboveconstproject2=type({ name })
Note that what you pass to describe is essentially the ___ in must be ___. This allows error messages to compose better for unions, intersections etc.
There are ways to customize the full structure of the message but I will get into those more in the upcoming docs!
Request a feature
Is it possible to add a simple error message to a field?
🤷 Motivation
It would be great to simply setup a default error message.
💡 Solution
The text was updated successfully, but these errors were encountered: