joi
joi copied to clipboard
ObjectSchema.describe() has incorrect typing
Support plan
- is this issue currently blocking your project? (yes/no): no
- is this issue affecting a production system? (yes/no): no
Context
- node version: 18
- module version with issue: 17.6.0
- last module version without issue: don't know
-
environment (e.g. node, browser, native):
ts-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?
I am trying to use the ObjectSchema.describe
function in the way that the typings suggest I could.
The object returned by ObjectSchema.describe
does not match it's corresponding type definition:
import joi from 'joi'; // 17.6.0
const myObj = joi.object({foo: joi.string().description('bar')});
myObj.describe();
What was the result you got?
{ type: 'object', keys: { foo: { type: 'string', flags: [Object] } } }
What result did you expect?
An object without the keys
property, matching the Description
type here.
In my repo I extended the describe types https://github.com/mrjono1/joi-to-typescript/blob/master/src/joiDescribeTypes.ts this may help as I was able to make these types recursive. This may help you
Ran into this today, I was disappointed to find the runtime object does not match the type in the d.ts file. A fix would be very appreciated 🙏