Search code examples
typescriptnode.js-stream

Node.js Stream on Typescript: supplied parameters do not match any signature of call target


In typescript I was trying to implement custom transform stream. But it was giving me typescript error supplied parameters do not match any signature of call target when I call super contructor with options.

var Transform = require('stream').Transform
export class Test extends Transform {
  constructor(options) {
        super(options);
    }
}

Any help will be appreciated. Thanks in advance !!


Solution

  • Because TypeScript does not know the type of the constructor of Transform when you are resolving it using require. You can use the import syntax to import Transform:

    import { Transform, TransformOptions } from "stream";
    
    export class Test extends Transform {
        constructor(options: TransformOptions) {
            super(options);
        }
    }
    

    Make sure you have the typings for node installed:

    npm install --save-dev @types/node