Open
Description
A handy way to wait for an event with node.js is to use the once
function in the events
module.
e.g. await once(bottleneck, 'empty');
to wait for the bottleneck empty
event using promises.
However, doing this results in a type error:
TS2769: No overload matches this call.
Overload 1 of 2, '(emitter: NodeEventTarget, event: string | symbol): Promise<any[]>', gave the following error.
Argument of type 'Bottleneck' is not assignable to parameter of type 'NodeEventTarget'.
The types returned by 'once(...)' are incompatible between these types.
Type 'void' is not assignable to type 'NodeEventTarget'.
Overload 2 of 2, '(emitter: DOMEventTarget, event: string): Promise<any[]>', gave the following error.
Argument of type 'Bottleneck' is not assignable to parameter of type 'DOMEventTarget'.
Property 'addEventListener' is missing in type 'Bottleneck' but required in type 'DOMEventTarget'.
events.d.ts(14, 9): 'addEventListener' is declared here.
This seems to be because once
is supposed to return the event emitter itself but in Bottleneck is declared as returning void
.
Also, even if I ignore the type error, once
still never resolves because Bottleneck doesn't fully implement the expected EventEmitter
protocol. I wonder if it would make sense to check if there's a native EventEmitter
available in the environment somehow and use that if it is there.
Metadata
Assignees
Labels
No labels
Activity