无法将名称空间“ Boom”用作类型

noo*_*oob 3 javascript node.js typescript hapijs typescript-typings

我正在使用hapi我的node + typescript项目之一。由于“裸”包的弃用,我试图更新hapi到新的@hapi/hapi包。我已更改@types/hapi@types/hapi__hapi

更新后,我开始出现TypeScript错误-

node_modules/@types/hapi__hapi/index.d.ts:514:32 - error TS2709: Cannot use namespace 'Boom' as a type.

514     response: ResponseObject | Boom;
                                   ~~~~

node_modules/@types/hapi__hapi/index.d.ts:4050:18 - error TS2709: Cannot use namespace 'Boom' as a type.

4050         (Error | Boom) |
                      ~~~~


Found 2 errors.
Run Code Online (Sandbox Code Playgroud)

Here's the dependencies I have in package.json -

{
...
"devDependencies": {
    ...
    "@types/hapi__boom": "7.4.1",
    "@types/hapi__hapi": "18.2.5",
    "@types/hapi__joi": "16.0.1",
    "@types/nock": "10.0.3",
    "@typescript-eslint/eslint-plugin": "2.4.0",
    "jest": "24.9.0",
    "nock": "11.4.0",
    "nodemon": "1.19.4",
    "prettier": "1.18.2",
    "typescript": "3.6.4"
  },
  "dependencies": {
    ...
    "@hapi/boom": "8.0.1",
    "@hapi/hapi": "18.4.0",
    "@hapi/joi": "16.1.7",
    "axios": "0.19.0",
    "axios-retry": "3.1.2"
  },
...
}
Run Code Online (Sandbox Code Playgroud)

I checked the node_modules/@types/hapi__hapi/index.d.ts file and it was importing Boom using the following way -

import * as Boom from '@hapi/boom';
Run Code Online (Sandbox Code Playgroud)

When I change it to

import { Boom } from '@hapi/boom';
Run Code Online (Sandbox Code Playgroud)

and it solved the error.

I can't change the index.d.ts file, as it's from @types/hapi__hapi package, but I want to solve this issue. Is there anything I can do to not have this error, such as downgrading to some specific version?

noo*_*oob 5

我检查了这些问题,发现@hapi/boom它们在7.x版本中包含破坏打字稿构建的类型。他们从7.x版本中删除了类型,但是将它们放回到8.x中,并且由于我正在使用@hapi/boom 8.0.1,所以它与现有类型冲突。

所有hapi生态系统都将在其中包含类型定义,但据我所知,其他软件包并未进行更新以做到这一点,因此,在不中断TypeScript构建的情况下解决此问题的唯一方法是降级@hapi/boom7.4.11

PS:我在发布问题后几分钟就发现了github问题,但如果有答案,我仍然愿意寻求更好的答案。