Reputation: 35
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:
Thank you in advance for the help !
Upvotes: 2
Views: 609
Reputation: 86
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.
Upvotes: 5