Node.js Typescript 上的流:提供的参数与调用目标的任何签名都不匹配
Node.js Stream on Typescript: supplied parameters do not match any signature of call target
在打字稿中,我试图实现自定义转换流。但是当我用 options
.
调用 super
构造函数时,它给我打字稿错误 supplied parameters do not match any signature of call target
var Transform = require('stream').Transform
export class Test extends Transform {
constructor(options) {
super(options);
}
}
如有任何帮助,我们将不胜感激。提前致谢!!
因为当您使用 require
解析它时,TypeScript 不知道 Transform
的构造函数的类型。您可以使用 import
语法导入 Transform
:
import { Transform, TransformOptions } from "stream";
export class Test extends Transform {
constructor(options: TransformOptions) {
super(options);
}
}
确保您安装了节点类型:
npm install --save-dev @types/node
在打字稿中,我试图实现自定义转换流。但是当我用 options
.
super
构造函数时,它给我打字稿错误 supplied parameters do not match any signature of call target
var Transform = require('stream').Transform
export class Test extends Transform {
constructor(options) {
super(options);
}
}
如有任何帮助,我们将不胜感激。提前致谢!!
因为当您使用 require
解析它时,TypeScript 不知道 Transform
的构造函数的类型。您可以使用 import
语法导入 Transform
:
import { Transform, TransformOptions } from "stream";
export class Test extends Transform {
constructor(options: TransformOptions) {
super(options);
}
}
确保您安装了节点类型:
npm install --save-dev @types/node