Open StephanMeijer opened 1 year ago
Types defined as following:
or
type ValidationResult<TSchema = any> = { error: undefined; warning?: ValidationError; value: TSchema; } | { error: ValidationError; warning?: ValidationError; value: undefined; }
import Joi from 'joi'; const schema = Joi.string() .required() .valid('only allowed value'); const result = schema.validate("a non-allowed value"); console.log(result);
{ value: 'a non-allowed value', error: [Error [ValidationError]: "value" must be [only allowed value]] { _original: 'a non-allowed value', details: [ [Object] ] } }
{ value: undefined, error: [Error [ValidationError]: "value" must be [only allowed value]] { _original: 'a non-allowed value', details: [ [Object] ] } }
FYI This seems to have the side effect that when destructuring the validation result value is always any, is this intentional?
value
any
Support plan
Context
Types defined as following:
or
What are you trying to achieve or the steps to reproduce?
What was the result you got?
What result did you expect?