Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Conversion 'GridFSBucketWriteStream' to type 'WritableStream' impossible?

Recently the conversion of GridFSBucketWriteStream to type WritableStream became impossible and leads to a types error.

const wst = svcMng.DBService.projectImageGrid.openUploadStream(image.name);
const uploadPromise = new Promise((resolve, reject) => {
    const read = new Readable({
        read() {
            this.push(image.data);
            this.push(null);
        }
    });

    read.on('error', (err) => {
        reject(err);
    });
    read.on('end', () => {
        resolve(null);
    });
    read.pipe(wst);
});
await uploadPromise;

read.pipe(wst) leads to: Argument of type 'GridFSBucketWriteStream' is not assignable to parameter of type 'WritableStream'.

wst is a GridFSBucketWriteStream type and should be convertible to WritableStream as GridFSBucketWriteStream class implements NodeJS.WritableStream.

Of course read.pipe(wst as any) solve the issue but I would like to avoid it.

read.pipe(wst as NodeJS.WritableStream) is not working also.

Versions:

  • mongoose: 6.1.4
  • typescript: 4.1.2
  • node v12.16.3

Thank you in advance for the help !

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

UPDATE: This issue has since been resolved (about 6 hours after my answer below) with mongodb version 4.3.0. (Here was the bug report: jira.mongodb.org/browse/NODE-3843)

I ran into the same problem and found a workaround. It was implicitly installing @types/node version 17.0.8 (See @types/node/package.json in node_modules). The breaking change is between Node 16 and Node 17 in the WritableStream interface. The end method used to return void and now returns this.

You can specify the version of Node types you want by running:

npm install --save-dev @types/node@16

It seems in the long term, the mongodb Node driver project needs to fix its compatibility with Node 17. But this workaround helped me for now.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!