Joi: Joi.only is not a function

Created on 13 Sep 2019  路  9Comments  路  Source: sideway/joi

Context

  • node version: 10.16.3
  • joi version: 16.0.0
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

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

const schema = Joi.only("A").required()

Which result you had ?

TypeError: Joi.only is not a function

What did you expect ?

No exception

non issue

All 9 comments

Yes, it's not available on the root, only on the types. I see you took it from the documentation, it's fixed.

thought so, thanks for the quick update!

@Marsup but isn't .valid an alias of .any and .valid is present on the root

Actually that's a fair point, my bad.

I think I will change my code to use .valid on types only and not on root, coz future fixes for this issue might break my code, that makes sense ?

You can do that in the meantime. I'll let @hueniverse see if my patch makes sense with his vision but other methods are there so pretty sure this one should too. Anyway you won't see a release immediately so it's best you move on with the longer form.

much appreciated, thanks.

only() is no longer used as an alias for valid(). This is a breaking change in v16.

missed to notice that in latest docs, thanks for clarification .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kevbook picture kevbook  路  4Comments

a-c-m picture a-c-m  路  3Comments

Dreamystify picture Dreamystify  路  4Comments

JbIPS picture JbIPS  路  4Comments

normancarcamo picture normancarcamo  路  3Comments