Open JakeElder opened 2 years ago
Hmm, I'm not sure why you would extend the EventEmitter
, but generally speaking…
I think this might be the issue (didn't test it, though):
abstract class BaseEmitter<T = {}> extends (EventEmitter as {
- new <T>(): TypedEmitter<T>;
+ new <T>(): TypedEmitter<T & BaseEvents>;
})<T & BaseEvents> {
Thank you for the reply @andywer - this results in a similar error as in my post. If I'm correct, that would make TypedEmitter<T & BaseEvents & BaseEvents>
as the final generic argument <T & BaseEvents>
I found this works, with sometimes clunky (but correct) error messages.
export abstract class DiscordBot<T = {}> extends (EventEmitter as {
new <T>(): TypedEmitter<BaseEvents> & TypedEmitter<T>;
})<T> {
Though I'm not sure my software design is correct either.
The code I am writing is an abstract class for Discord bots. Each of the bots should emit events like 'READY' once initialisation has completed, and I would like to be able to emit common events from methods in the abstract class, 'READY', 'COMMAND_RECEIVED', etc.
The concrete bot implementations should each be able to emit their own events too, 'BOT_SPECFIC_TASK_COMPLETE' etc.
This was easy with version 1.x of this library, where you used interfaces instead of types, and then you could easily just create generic with type constraints that said <TEvents extends IBaseEvents>
@sp00x I don't quite understand. The TypedEmitter
is still an interface, just that the BaseEvents
are now a type alias, but that's just used as a type constraint. <TEvents extends IBaseEvents>
should work just fine, not?
Sorry, just saw #32.
Thank you for the package! I'm struggling to achieve something that I'm sure is an easy task for some. Is this possible?
How can I extend an abstract
EventEmitter
class, with common events?Example:
I've tried
And lots of other things. The above results in
Argument of type '[string]' is not assignable to parameter of type 'Arguments<(T & BaseEvents)["BASE_EVENT"]>'.
For line