I am using hapi
for one of my node+typescript project. I am trying to update hapi
to the new @hapi/hapi
package, due to the deprecation of the "naked" packages. I've changed @types/hapi
to @types/hapi__hapi
.
As soon as I updated, I started getting the TypeScript error -
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.
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"
},
...
}
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';
When I change it to
import { Boom } from '@hapi/boom';
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?
I checked the issues at @hapi/boom
and they included types in 7.x release which were breaking typescript build. They removed types from 7.x releases, but put them back in 8.x, and since I was using @hapi/boom 8.0.1
, it was conflicting with the existing types.
All the hapi ecosystem is going to include type definitions in them, but other packages are not updated to do it (as far as I could tell), thus the only way to resolve this issue without breaking breaking TypeScript builds is to downgrade @hapi/boom
to 7.4.11
.
PS: I found out the github issues minutes after posting the question, but I am still open for better answers, if there is one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With