Skip to content

Typescript types not augmenting Joi.object and schema.validate #2606

@FrenchMajesty

Description

@FrenchMajesty

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: v10.16
  • module version with issue: 17.4.0
  • last module version without issue: 17.4.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?

The library supports Typescript which is awesome but there's a few places where it doesn't behave as expected. For example in this given code:

    const schema = Joi.object<UserAPI.Register.Teacher>({
      userId: Joi.string().required(),
      email: Joi.string().email().required(),
      password: Joi.string().min(3).required(),
      type: Joi.string(),
      name: Joi.object({
        givenName: Joi.string(),
        familyName: Joi.string(),
      }).required(),
    });
    
    const { error, value } = schema.validate(request.body);

What would you expect?

I would expect to get a TS error if I am missing some keys defined in UserAPI.Register.Teacher type but there are none, it also doesn't provide intelliSense.

What happens?

Currently it does nothing.

What would you expect?

Furthermore, when I run schema.validate I would also expect the value key returned to be of type UserAPI.Register.Teacher but it comes back as any.

What happens?

const schema: Joi.ObjectSchema<UserAPI.Register.Teacher>

The schema itself has the right type if I hover over it but then the type info provided is not making its way down the validation lifecycle.

Metadata

Metadata

Assignees

Labels

typesTypeScript type definitions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions