joi icon indicating copy to clipboard operation
joi copied to clipboard

Typescript typing on `Joi.string().validate(...)`

Open Nokel81 opened this issue 2 years ago • 2 comments

Context

  • node version: 14.17.X
  • module version with issue: 17.5.0
  • last module version without issue: 17.5.0
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information:

What are you trying to achieve or the steps to reproduce?

const schema = Joi.string();
const result = schema.validate(getUnknownValue());

if (!result.error) {
  result.value; // typed as `any` but should be `string`
}

What was the result you got?

The result of Joi.string().validate(...) has the field value typed as any.

What result did you expect?

The result of Joi.string().validate(...) has the field value typed as string.

Nokel81 avatar Mar 14 '22 19:03 Nokel81

On a related note, it also seems strange that Joi.array() only every validates to any. Not even any[]

Nokel81 avatar Mar 14 '22 19:03 Nokel81

Yes please.

imjamesb avatar Aug 30 '22 22:08 imjamesb

This seems to be fixed by #2860 🎉

Nokel81 avatar Oct 11 '22 13:10 Nokel81

Thanks for mentioning it @Nokel81, that's one less issue 😅

Marsup avatar Oct 11 '22 14:10 Marsup