Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The EventEmitter3 library does not seem to support generic type merging #270

Open
kamenomi-dev opened this issue Jul 21, 2024 · 1 comment

Comments

@kamenomi-dev
Copy link

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

@YaminZheng
Copy link

我有相同的问题,这个是 ts 的问题吗,说实话,不知道为什么会抛出这样的 ts 错误

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants