Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda