Is there a fix for "Must be invoked on a Joi instance"?
import { object, string, number, array } from '@hapi/joi';
...
throws Must be invoked on a Joi instance.
There has been an issue about it, that has been locked for some reason: https://github.com/hapijs/joi/issues/1349
Has anything changed since then? Is there a fix for this bug now?
Ok, this seems to work:
import Joi from '@hapi/joi';
// import { object, string, number, array, any } from '@hapi/joi';
const object = (args) => Joi.object(args);
const string = () => Joi.string();
const number = () => Joi.number();
const array = () => Joi.array();
const any = () => Joi.any();
There's also types() function.
https://hapi.dev/family/joi/api/?v=17.1.0#types
But it returns different API.
very helpful
the destructuring could be your issue, you can instead import Joi from @hapi/joi and access the keys directly, like so Joi.object(), Joi.string()...
For anyone stumbling on this issue, this was implemented long ago with https://joi.dev/api/?v=17.5.0#types