joi icon indicating copy to clipboard operation
joi copied to clipboard

fix value type on validation result

Open mastery-benjamin-palko opened this issue 4 months ago • 5 comments

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

mastery-benjamin-palko avatar Mar 07 '24 15:03 mastery-benjamin-palko