Skip to content

Issue with subclasses #6

@Valandur

Description

@Valandur

Hi, thanks for the great library 👍

I have a question about the subclasses with different events example that you provided in the readme:

The example works when calling the events from outside the class, but not from within the class itself. Specifically, if I alter the example to be as follows:

class Animal<E extends ListenerSignature<E> = ListenerSignature<unknown>> extends TypedEmitter<{ spawn: () => void } & E> {
	public constructor() {
		super();
	}

	private doSpawn() {
		this.emit('spawn');
	}
}

class Frog<E extends ListenerSignature<E>> extends Animal<{ jump: (testing: boolean) => void } & E> {}
class Bird<E extends ListenerSignature<E>> extends Animal<{ fly: () => void } & E> {}

Then the compiler fails at the this.emit('spawn'); line with the error: Argument of type '[]' is not assignable to parameter of type 'Parameters<({ spawn: () => void; } & E)["spawn"]>'.

I'm assuming this is because of some constraint that can't be applied, but I can't seem to wrap my head around it. Is there any way to solve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions