Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#69535 [@types/node] Make it possible to us…
Browse files Browse the repository at this point in the history
…e `static EventEmitter.on` with `EventTarget` by @sgrishchenko
  • Loading branch information
sgrishchenko authored Jun 5, 2024
1 parent 701884e commit dc1b21c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions types/node/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ declare module "events" {
*/
static on(
emitter: NodeJS.EventEmitter,
eventName: string | symbol,
options?: StaticEventEmitterOptions,
): AsyncIterableIterator<any>;
static on(
emitter: EventTarget,
eventName: string,
options?: StaticEventEmitterOptions,
): AsyncIterableIterator<any>;
Expand Down
14 changes: 14 additions & 0 deletions types/node/test/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ async function test() {
events.on(new events.EventEmitter(), "test", { signal: new AbortController().signal });
}

async function testWithSymbol() {
for await (const e of events.on(new events.EventEmitter(), Symbol("test"))) {
console.log(e);
}
events.on(new events.EventEmitter(), Symbol("test"), { signal: new AbortController().signal });
}

async function testEventTarget() {
for await (const e of events.on(new EventTarget(), "test")) {
console.log(e);
}
events.on(new EventTarget(), "test", { signal: new AbortController().signal });
}

{
emitter.on(events.errorMonitor, listener);
emitter.on(events.EventEmitter.errorMonitor, listener);
Expand Down

0 comments on commit dc1b21c

Please sign in to comment.