Skip to content

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

@kamenomi-dev

Description

@kamenomi-dev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions