typescriptnode-mongodb-native

Error Importing "mongodb" with typescript


When compiling any typescript program that just imports mongodb, i get 12 errors like:

node_modules/mongodb/mongodb.d.ts:3309:5 - error TS2416: Property 'end' in type 'GridFSBucketWriteStream' is not assignable to the same property in base type 'WritableStream'

To reproduce is simple with node TLS (v16.13.1), & a empty directory, just run:

npm i mongodb typescript
echo "import mongodb  from 'mongodb'" > index.ts
npx tsc index

Solution

  • Looks like mongodb npm released 4.3.0 last night (2022-01-06) that now resolves this issue! changelog includes the issue here: #3088

    v4 now compiles without these errors!