Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Typescript 4.8: how to extends Node stream.Writable

I am trying to create a simple class implementing Node stream.Writable but it seems I can’t get the syntax right, the compiler is always complaining:

enter image description here

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

I am not sure exactly what I am doing wrong. Any hint?

node: 16.17.0
@types/node: 16.11.64
typescript: 4.8.3

>Solution :

You need to declare the _write method outside of the constructor.

class MyWritable extends Writable {
  constructor() {
    super({ objectMode: true });
  }
  
  // moved outside the constructor function.
  _write(chunk: any, encoding: BufferEncoding, callback: () => void) {
    //...
  }
}

Which works without errors. See Playground

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading