Repository: sindresorhus/emittery (js)

Issue:
`.emit()` should not receive the returned value from `.on()`
I noticed that you can return a value from an event handler, e.g.,

```javascript
event.on("myEvent", () => 123);
const value = await event.emit("myEvent");
value[0] === 123; // true
```

But the `Emittery.Typed` types don't support the return type, so typescript thinks `value` is always `void`.

Is this a feature that you'd like to be supported in the TypeScript types? If so, I can probably find some time to put a PR together. Are there any gotchas I should be aware of?

I hacked together something to make it "work" for my code base (it's not quite right), though this would result in breaking changes:

```typescript
class Typed<EventDataMap extends Events, EmptyEvents extends EventName = never> extends Emittery.Typed {
	on<Name extends EventNameFromDataMap<EventDataMap>>(eventName: Name, listener: (eventData: Parameters<EventDataMap[Name]>[0]) => void): Emittery.UnsubscribeFn;
	on<Name extends EmptyEvents>(eventName: Name, listener: () => void): Emittery.UnsubscribeFn;

	events<Name extends EventNameFromDataMap<EventDataMap>>(eventName: Name): AsyncIterableIterator<Parameters<EventDataMap[Name]>[0]>;

	once<Name extends EventNameFromDataMap<EventDataMap>>(eventName: Name): Promise<ReturnType<EventDataMap[Name]>>;
	once<Name extends EmptyEvents>(eventName: Name): Promise<ReturnType<EventDataMap[Name]>>;

	off<Name extends EventNameFromDataMap<EventDataMap>>(eventName: Name, listener: (eventData: Parameters<EventDataMap[Name]>[0]) => void): void;
	off<Name extends EmptyEvents>(eventName: Name, listener: () => void): void;

	onAny(listener: (eventName: EventNameFromDataMap<EventDataMap> | EmptyEvents, eventData?: EventDataMap[EventNameFromDataMap<EventDataMap>]) => void): Emittery.UnsubscribeFn;
	anyEvent(): AsyncIterableIterator<[EventNameFromDataMap<EventDataMap>, EventDataMap[EventNameFromDataMap<EventDataMap>]]>;

	offAny(listener: (eventName: EventNameFromDataMap<EventDataMap> | EmptyEvents, eventData?: EventDataMap[EventNameFromDataMap<EventDataMap>]) => void): void;

	emit<Name extends EventNameFromDataMap<EventDataMap>>(eventName: Name, eventData: Parameters<EventDataMap[Name]>[0]): Promise<ReturnType<EventDataMap[Name]>>;
	emit<Name extends EmptyEvents>(eventName: Name): Promise<ReturnType<EventDataMap[Name]>>;

	emitSerial<Name extends EventNameFromDataMap<EventDataMap>>(eventName: Name, eventData: Parameters<EventDataMap[Name]>[0]): Promise<ReturnType<EventDataMap[Name]>>;
	emitSerial<Name extends EmptyEvents>(eventName: Name): Promise<ReturnType<EventDataMap[Name]>>;
}
```

Pull request description:
Ensure `.emit()` doesn't return a value
Fixes #55 

Just replaced the `return` statement and added a couple of tests.

Patch:
diff --git a/index.js b/index.js
index 5ddd3db..c4bb6ae 100644
--- a/index.js
+++ b/index.js
@@ -236,7 +236,7 @@ class Emittery {
 		const staticAnyListeners = isListenerSymbol(eventName) ? [] : [...anyListeners];
 
 		await resolvedPromise;
-		return Promise.all([
+		await Promise.all([
 			...staticListeners.map(async listener => {
 				if (listeners.has(listener)) {
 					return listener(eventData);


Test patch:
diff --git a/test/index.js b/test/index.js
index 6b1d838..e589f62 100644
--- a/test/index.js
+++ b/test/index.js
@@ -352,6 +352,30 @@ test('emit() - calls listeners subscribed when emit() was invoked', async t => {
 	t.deepEqual(calls, [1, 1, 2, 3, 2, 4, 5, 2, 4, 7, 6, 2, 4, 7, 6, 9, 2, 4, 7, 6, 9]);
 });
 
+test('emit() - returns undefined', async t => {
+	const emitter = new Emittery();
+
+	emitter.on('🦄', () => '🌈');
+	t.is(await emitter.emit('🦄'), undefined);
+
+	emitter.on('🦄🦄', async () => '🌈');
+	t.is(await emitter.emit('🦄🦄'), undefined);
+});
+
+test('emit() - throws an error if any listener throws', async t => {
+	const emitter = new Emittery();
+
+	emitter.on('🦄', () => {
+		throw new Error('🌈');
+	});
+	await t.throwsAsync(emitter.emit('🦄'), {instanceOf: Error});
+
+	emitter.on('🦄🦄', async () => {
+		throw new Error('🌈');
+	});
+	await t.throwsAsync(emitter.emit('🦄🦄'), {instanceOf: Error});
+});
+
 test.cb('emitSerial()', t => {
 	t.plan(1);