joi
joi copied to clipboard
fix value type on validation result
The value property returned from .validate
is always any, which forces casting to the expected type.
The value should always be known (TSchema) and the error property will be optional, check if error is falsey to determine if value has been properly validated.
Example:
const { value, error } = <schema>.validate(<obj>);
if (error) {
console.error(error);
return;
}
// do stuff...
Related to #2677