andywer / typed-emitter

🔩 Type-safe event emitter interface for TypeScript
MIT License
268 stars 24 forks source link

optional context not typed #42

Open ghclark2 opened 1 year ago

ghclark2 commented 1 year ago

This is great for providing typed events, however, there doesn't seem to be any allowance for the optional context that can be passed to an event.

PlayBus.on('botDestroyed', this.attemptSpawn, this)

The above code is correct and passes the context correctly to eventemitter3, but typescript complains about the 'this'. Is this a mistake? Should for example:

on<E extends keyof Events> (event: E, listener: Events[E]): this

instead be:

on<E extends keyof Events> (event: E, listener: Events[E], context?: any): this