TCMiranda / joi-extract-type

Provides native type extraction from Joi schemas for Typescript
MIT License
151 stars 27 forks source link

Namespace 'Joi' has no exported member 'extractType'. #38

Closed 2color closed 2 years ago

2color commented 4 years ago

Dependencies versions

@types/hapi__hapi: 19.0.3" @types/hapi__joi: 17.1.4 joi-extract-type: "15.0.8" typescript: "3.9.6"

Usage example


import Hapi from '@hapi/hapi'
import * as Joi from '@hapi/joi'
import 'joi-extract-type'

const registerValidator = Joi.object({
  name: Joi.string().required(),
  email: Joi.string().email().required(),
  social: Joi.object({
    facebook: Joi.string().optional(),
    twitter: Joi.string().optional(),
    github: Joi.string().optional(),
    website: Joi.string().optional(),
  }).optional(),

type RegisterInput = Joi.extractType<typeof registerValidator>;

server.route([
      {
        method: 'POST',
        path: '/register',
        handler: registerHandler,
        options: {
          auth: false,
          validate: {
            payload: registerValidator,
            failAction: 'error',
          },
        },
      },
    ])

However, I'm getting the following error when trying to compile:

error TS2694: Namespace 'Joi' has no exported member 'extractType'.

42 type RegisterInput = Joi.extractType<typeof registerValidator>;
                            ~~~~~~~~~~~

Any reason why module augmentation isn't working?

TCMiranda commented 4 years ago

Hi @2color, unfortunately, we don't have integration with Joi >= 16, which I believe is the source of your error. You can follow up or help with this issue here: https://github.com/TCMiranda/joi-extract-type/issues/22

Thank you

erickssonxD commented 3 years ago

@TCMiranda This should be clearly shown in README, to avoid this kind of unnecesary errors