Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not compatible with node.js "once" #164

Open
dobesv opened this issue Aug 20, 2020 · 0 comments · May be fixed by #165
Open

Not compatible with node.js "once" #164

dobesv opened this issue Aug 20, 2020 · 0 comments · May be fixed by #165

Comments

@dobesv
Copy link
Contributor

dobesv commented Aug 20, 2020

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.

@dobesv dobesv changed the title Types not compatible with node.js "once" Not compatible with node.js "once" Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant