我正在尝试创建一个实现节点stream.Writable的简单类,但是我似乎无法正确地理解语法,编译器总是抱怨:



我不知道我到底做错了什么。有什么暗示吗?
node:16.17.0
@types/node:16.11.64
typescript:4.8.3
发布于 2022-10-04 17:23:57
您需要在构造函数之外声明_write方法。
class MyWritable extends Writable {
constructor() {
super({ objectMode: true });
}
// moved outside the constructor function.
_write(chunk: any, encoding: BufferEncoding, callback: () => void) {
//...
}
}没有错误。见游乐场
https://stackoverflow.com/questions/73951364
复制相似问题