eventemitter3
eventemitter3 copied to clipboard
The EventEmitter3 library does not seem to support generic type merging
I initialize the class with the following code
import EventEmitter from "eventemitter3";
type defaultType = {
"test"(): void;
};
class subClass<
Z extends { [props: string]: (...args: any[]) => any },
> extends EventEmitter<Z & defaultType> {
constructor() {
super();
let func = () => {};
this.on("test", func);
this.emit("test");
this.off("test", func);
}
}
But, in the following line of code:
this.on("test", func);
this.emit("test");
this.off("test", func);
There is an error in the parameters:
Argument of type 'string' is not assignable to parameter of type 'EventNames<Z & defaultType>'.typescript(2345)
I don't know why, what will cause this problem? CodeSandbox: URL
我有相同的问题,这个是 ts 的问题吗,说实话,不知道为什么会抛出这样的 ts 错误