EventEmitter interface inconsistent
See original GitHub issueDescribe the bug
EventEmitter
interface is based on NodeJS events
module.
core-event-emitter
module returns custom EventEmitter
class which does not implement interface and native emitter is not accessible (private).
So, it’s possible to have the following error when calling native emitter functions not implemented by custom emitter:
(node:89665) UnhandledPromiseRejectionWarning: TypeError: emitter.off is not a function
To Reproduce
In my example I tried to call the off
function of native emitter.
Expected behavior
Either a typescript error must be thrown at compile time.
Or off
function of native emitter is available on custom class
Or all native emitter function are available.
I can make the fix asap after best solution has been chosen:
- re-write
EventEmitter
interface with custom class methods - add
off
method to custom class - expose native emitter from custom class.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Narrowing down class methods, typing without extending or ...
Class 'ChildEmitter' incorrectly implements interface 'TypedEmitter'. Types of property 'on' are incompatible. Type '(eventName: string | symbol ...
Read more >EventEmitters must behave appropriately if a handler raises ...
EventEmitter events are supposed to be a one-way communcation channel from the emitter to the handler. This paradigm breaks if the handler throws...
Read more >typed-emitter - npm
Strictly typed event emitter interface for TypeScript. Code size: Zero bytes - Just the typings, no implementation. Use the default event ...
Read more >On EventEmitter In node.js - Web Reflection
On EventEmitter In node.js · on() is a shortcut for addListener but there is no off() as removeListener's shortcut (inconsistent) · add/removeListener is...
Read more >asyncly - Bountysource
I had a situation where something was inheriting from EventEmitter, ... Currently EventEmitter2 can't be assigned directly to a EventEmitter interface:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you encounter an issue and already have a solution just submit a PR with it otherwise small issues like that will just be resolved.
@faustbrian thank you for fixing this quickly.
It would have been also great to discuss it a little bit more before.
1/ The done “bugfix” doesn’t really fix the underlying issue: the Ark
emitter.EventEmitter
type is not a NodeJSevents.EventEmitter
and several other methods are missing, such asremoveAllListeners
,listeners
,addListener
… These methods used to be available witheventemitter3
, removed by #2329, which have introduced an API breaking change and have impacted our Unik-Name implementation of Ark core (see https://github.com/ArkEcosystem/AIPs/issues/70).Another solution:
emitter.EventEmitter
could inherit fromevents.EventEmitter
and override a few methods to update the max count of listeners.2/ @nigui had already done a private fix when he described the issue. So a fix for this issue has been done twice. This can bee seen as “lost time”. Was this issue critical enough to fix it so quickly (5h)?
So, for the next time, can you please tell us:
Thank you