Home > Enterprise >  Typescript 4.8: how to extends Node stream.Writable
Typescript 4.8: how to extends Node stream.Writable

Time:10-05

I am trying to create a simple class implementing enter image description here

enter image description here

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

CodePudding user response:

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

  • Related