Capítulo 16 de 29
A validator's return value can be any truthy value, not just a string — numbers, booleans, objects, or arrays all count as "there is an error," with full type inference on whatever shape you choose.
false/undefined/null mean "valid" — this is the whole contract, no special "error" wrapper type required.{ message, severity, code } is just as valid a return as a plain string, and TypeScript infers that exact shape for consumers.<form.Field
name="email"
validators={{
onChange: ({ value }) => {
if (!value.includes('@')) {
return { message: 'Invalid email format', severity: 'error', code: 1001 }
}
return undefined
},
}}
/>
severity or look up code in a translation table.0 and '' would count as "valid" if accidentally returned from a validator meant to signal an error — be deliberate about always returning a real message/object or undefined, never an ambiguous falsy value from a bug.err.severity/err.code — no manual typing needed.ValidationError (typed as unknown precisely to allow this flexibility).