Fix dependabot issues

This commit is contained in:
Andrew Eisenberg 2021-10-21 15:24:20 -07:00
parent c89d9bd8b0
commit 531c6ba7c8
705 changed files with 53406 additions and 20466 deletions

274
node_modules/emittery/index.d.ts generated vendored
View file

@ -5,24 +5,51 @@ Symbol event names can be used to avoid name collisions when your classes are ex
*/
type EventName = string | symbol;
declare class Emittery {
/**
In TypeScript, it returns a decorator which mixins `Emittery` as property `emitteryPropertyName` and `methodNames`, or all `Emittery` methods if `methodNames` is not defined, into the target class.
// Helper type for turning the passed `EventData` type map into a list of string keys that don't require data alongside the event name when emitting. Uses the same trick that `Omit` does internally to filter keys by building a map of keys to keys we want to keep, and then accessing all the keys to return just the list of keys we want to keep.
type DatalessEventNames<EventData> = {
[Key in keyof EventData]: EventData[Key] extends undefined ? Key : never;
}[keyof EventData];
@example
```
import Emittery = require('emittery');
declare const listenerAdded: unique symbol;
declare const listenerRemoved: unique symbol;
type OmnipresentEventData = {[listenerAdded]: Emittery.ListenerChangedData; [listenerRemoved]: Emittery.ListenerChangedData};
@Emittery.mixin('emittery')
class MyClass {}
/**
Emittery is a strictly typed, fully async EventEmitter implementation. Event listeners can be registered with `on` or `once`, and events can be emitted with `emit`.
const instance = new MyClass();
`Emittery` has a generic `EventData` type that can be provided by users to strongly type the list of events and the data passed to the listeners for those events. Pass an interface of {[eventName]: undefined | <eventArg>}, with all the event names as the keys and the values as the type of the argument passed to listeners if there is one, or `undefined` if there isn't.
instance.emit('event');
```
*/
static mixin(emitteryPropertyName: string, methodNames?: readonly string[]): Function;
@example
```
import Emittery = require('emittery');
const emitter = new Emittery<
// Pass `{[eventName: <string | symbol>]: undefined | <eventArg>}` as the first type argument for events that pass data to their listeners.
// A value of `undefined` in this map means the event listeners should expect no data, and a type other than `undefined` means the listeners will receive one argument of that type.
{
open: string,
close: undefined
}
>();
// Typechecks just fine because the data type for the `open` event is `string`.
emitter.emit('open', 'foo\n');
// Typechecks just fine because `close` is present but points to undefined in the event data type map.
emitter.emit('close');
// TS compilation error because `1` isn't assignable to `string`.
emitter.emit('open', 1);
// TS compilation error because `other` isn't defined in the event data type map.
emitter.emit('other');
```
*/
declare class Emittery<
EventData = Record<string, any>, // When https://github.com/microsoft/TypeScript/issues/1863 ships, we can switch this to have an index signature including Symbols. If you want to use symbol keys right now, you need to pass an interface with those symbol keys explicitly listed.
AllEventData = EventData & OmnipresentEventData,
DatalessEvents = DatalessEventNames<EventData>
> {
/**
Fires when an event listener was added.
@ -47,7 +74,7 @@ declare class Emittery {
});
```
*/
static readonly listenerAdded: unique symbol;
static readonly listenerAdded: typeof listenerAdded;
/**
Fires when an event listener was removed.
@ -75,17 +102,56 @@ declare class Emittery {
off();
```
*/
static readonly listenerRemoved: unique symbol;
static readonly listenerRemoved: typeof listenerRemoved;
/**
Subscribe to an event.
In TypeScript, it returns a decorator which mixins `Emittery` as property `emitteryPropertyName` and `methodNames`, or all `Emittery` methods if `methodNames` is not defined, into the target class.
@example
```
import Emittery = require('emittery');
@Emittery.mixin('emittery')
class MyClass {}
const instance = new MyClass();
instance.emit('event');
```
*/
static mixin(
emitteryPropertyName: string | symbol,
methodNames?: readonly string[]
): <T extends { new (): any }>(klass: T) => T; // eslint-disable-line @typescript-eslint/prefer-function-type
/**
Subscribe to one or more events.
Using the same listener multiple times for the same event will result in only one method call per emitted event.
@returns An unsubscribe method.
@example
```
import Emittery = require('emittery');
const emitter = new Emittery();
emitter.on('🦄', data => {
console.log(data);
});
emitter.on(['🦄', '🐶'], data => {
console.log(data);
});
emitter.emit('🦄', '🌈'); // log => '🌈' x2
emitter.emit('🐶', '🍖'); // log => '🍖'
```
*/
on(eventName: typeof Emittery.listenerAdded | typeof Emittery.listenerRemoved, listener: (eventData: Emittery.ListenerChangedData) => void): Emittery.UnsubscribeFn
on(eventName: EventName, listener: (eventData?: unknown) => void): Emittery.UnsubscribeFn;
on<Name extends keyof AllEventData>(
eventName: Name,
listener: (eventData: AllEventData[Name]) => void | Promise<void>
): Emittery.UnsubscribeFn;
/**
Get an async iterator which buffers data each time an event is emitted.
@ -139,29 +205,105 @@ declare class Emittery {
}
}
```
It accepts multiple event names.
@example
```
import Emittery = require('emittery');
const emitter = new Emittery();
const iterator = emitter.events(['🦄', '🦊']);
emitter.emit('🦄', '🌈1'); // Buffered
emitter.emit('🦊', '🌈2'); // Buffered
iterator
.next()
.then(({value, done}) => {
// done === false
// value === '🌈1'
return iterator.next();
})
.then(({value, done}) => {
// done === false
// value === '🌈2'
// Revoke subscription
return iterator.return();
})
.then(({done}) => {
// done === true
});
```
*/
events(eventName: EventName): AsyncIterableIterator<unknown>
events<Name extends keyof EventData>(
eventName: Name | Name[]
): AsyncIterableIterator<EventData[Name]>;
/**
Remove an event subscription.
Remove one or more event subscriptions.
@example
```
import Emittery = require('emittery');
const emitter = new Emittery();
const listener = data => console.log(data);
(async () => {
emitter.on(['🦄', '🐶', '🦊'], listener);
await emitter.emit('🦄', 'a');
await emitter.emit('🐶', 'b');
await emitter.emit('🦊', 'c');
emitter.off('🦄', listener);
emitter.off(['🐶', '🦊'], listener);
await emitter.emit('🦄', 'a'); // nothing happens
await emitter.emit('🐶', 'b'); // nothing happens
await emitter.emit('🦊', 'c'); // nothing happens
})();
```
*/
off(eventName: EventName, listener: (eventData?: unknown) => void): void;
off<Name extends keyof AllEventData>(
eventName: Name,
listener: (eventData: AllEventData[Name]) => void | Promise<void>
): void;
/**
Subscribe to an event only once. It will be unsubscribed after the first
Subscribe to one or more events only once. It will be unsubscribed after the first
event.
@returns The event data when `eventName` is emitted.
@example
```
import Emittery = require('emittery');
const emitter = new Emittery();
emitter.once('🦄').then(data => {
console.log(data);
//=> '🌈'
});
emitter.once(['🦄', '🐶']).then(data => {
console.log(data);
});
emitter.emit('🦄', '🌈'); // Logs `🌈` twice
emitter.emit('🐶', '🍖'); // Nothing happens
```
*/
once(eventName: typeof Emittery.listenerAdded | typeof Emittery.listenerRemoved): Promise<Emittery.ListenerChangedData>
once(eventName: EventName): Promise<unknown>;
once<Name extends keyof AllEventData>(eventName: Name): Promise<AllEventData[Name]>;
/**
Trigger an event asynchronously, optionally with some data. Listeners are called in the order they were added, but executed concurrently.
@returns A promise that resolves when all the event listeners are done. *Done* meaning executed if synchronous or resolved when an async/promise-returning function. You usually wouldn't want to wait for this, but you could for example catch possible errors. If any of the listeners throw/reject, the returned promise will be rejected with the error, but the other listeners will not be affected.
*/
emit(eventName: EventName, eventData?: unknown): Promise<void>;
emit<Name extends DatalessEvents>(eventName: Name): Promise<void>;
emit<Name extends keyof EventData>(
eventName: Name,
eventData: EventData[Name]
): Promise<void>;
/**
Same as `emit()`, but it waits for each listener to resolve before triggering the next one. This can be useful if your events depend on each other. Although ideally they should not. Prefer `emit()` whenever possible.
@ -170,14 +312,23 @@ declare class Emittery {
@returns A promise that resolves when all the event listeners are done.
*/
emitSerial(eventName: EventName, eventData?: unknown): Promise<void>;
emitSerial<Name extends DatalessEvents>(eventName: Name): Promise<void>;
emitSerial<Name extends keyof EventData>(
eventName: Name,
eventData: EventData[Name]
): Promise<void>;
/**
Subscribe to be notified about any event.
@returns A method to unsubscribe.
*/
onAny(listener: (eventName: EventName, eventData?: unknown) => unknown): Emittery.UnsubscribeFn;
onAny(
listener: (
eventName: keyof EventData,
eventData: EventData[keyof EventData]
) => void | Promise<void>
): Emittery.UnsubscribeFn;
/**
Get an async iterator which buffers a tuple of an event name and data each time an event is emitted.
@ -213,24 +364,31 @@ declare class Emittery {
});
```
*/
anyEvent(): AsyncIterableIterator<unknown>
anyEvent(): AsyncIterableIterator<
[keyof EventData, EventData[keyof EventData]]
>;
/**
Remove an `onAny` subscription.
*/
offAny(listener: (eventName: EventName, eventData?: unknown) => void): void;
offAny(
listener: (
eventName: keyof EventData,
eventData: EventData[keyof EventData]
) => void | Promise<void>
): void;
/**
Clear all event listeners on the instance.
If `eventName` is given, only the listeners for that event are cleared.
*/
clearListeners(eventName?: EventName): void;
clearListeners(eventName?: keyof EventData): void;
/**
The number of listeners for the `eventName` or all events if not specified.
*/
listenerCount(eventName?: EventName): number;
listenerCount(eventName?: keyof EventData): number;
/**
Bind the given `methodNames`, or all `Emittery` methods if `methodNames` is not defined, into the `target` object.
@ -246,7 +404,7 @@ declare class Emittery {
object.emit('event');
```
*/
bindMethods(target: object, methodNames?: readonly string[]): void;
bindMethods(target: Record<string, unknown>, methodNames?: readonly string[]): void;
}
declare namespace Emittery {
@ -254,15 +412,6 @@ declare namespace Emittery {
Removes an event subscription.
*/
type UnsubscribeFn = () => void;
type EventNameFromDataMap<EventDataMap> = Extract<keyof EventDataMap, EventName>;
/**
Maps event names to their emitted data type.
*/
interface Events {
// Blocked by https://github.com/microsoft/TypeScript/issues/1863, should be
// `[eventName: EventName]: unknown;`
}
/**
The data provided as `eventData` when listening for `Emittery.listenerAdded` or `Emittery.listenerRemoved`.
@ -271,54 +420,13 @@ declare namespace Emittery {
/**
The listener that was added or removed.
*/
listener: (eventData?: unknown) => void;
listener: (eventData?: unknown) => void | Promise<void>;
/**
The name of the event that was added or removed if `.on()` or `.off()` was used, or `undefined` if `.onAny()` or `.offAny()` was used.
*/
eventName?: EventName;
}
/**
Async event emitter.
You must list supported events and the data type they emit, if any.
@example
```
import Emittery = require('emittery');
const emitter = new Emittery.Typed<{value: string}, 'open' | 'close'>();
emitter.emit('open');
emitter.emit('value', 'foo\n');
emitter.emit('value', 1); // TS compilation error
emitter.emit('end'); // TS compilation error
```
*/
class Typed<EventDataMap extends Events, EmptyEvents extends EventName = never> extends Emittery {
on<Name extends EventNameFromDataMap<EventDataMap>>(eventName: Name, listener: (eventData: EventDataMap[Name]) => void): Emittery.UnsubscribeFn;
on<Name extends EmptyEvents>(eventName: Name, listener: () => void): Emittery.UnsubscribeFn;
events<Name extends EventNameFromDataMap<EventDataMap>>(eventName: Name): AsyncIterableIterator<EventDataMap[Name]>;
once<Name extends EventNameFromDataMap<EventDataMap>>(eventName: Name): Promise<EventDataMap[Name]>;
once<Name extends EmptyEvents>(eventName: Name): Promise<void>;
off<Name extends EventNameFromDataMap<EventDataMap>>(eventName: Name, listener: (eventData: EventDataMap[Name]) => 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: EventDataMap[Name]): Promise<void>;
emit<Name extends EmptyEvents>(eventName: Name): Promise<void>;
emitSerial<Name extends EventNameFromDataMap<EventDataMap>>(eventName: Name, eventData: EventDataMap[Name]): Promise<void>;
emitSerial<Name extends EmptyEvents>(eventName: Name): Promise<void>;
}
}
export = Emittery;

159
node_modules/emittery/index.js generated vendored
View file

@ -31,7 +31,7 @@ function getListeners(instance, eventName) {
}
function getEventProducers(instance, eventName) {
const key = typeof eventName === 'string' ? eventName : anyProducer;
const key = typeof eventName === 'string' || typeof eventName === 'symbol' ? eventName : anyProducer;
const producers = producersMap.get(instance);
if (!producers.has(key)) {
producers.set(key, new Set());
@ -56,7 +56,9 @@ function enqueueProducers(instance, eventName, eventData) {
}
}
function iterator(instance, eventName) {
function iterator(instance, eventNames) {
eventNames = Array.isArray(eventNames) ? eventNames : [eventNames];
let isFinished = false;
let flush = () => {};
let queue = [];
@ -72,7 +74,9 @@ function iterator(instance, eventName) {
}
};
getEventProducers(instance, eventName).add(producer);
for (const eventName of eventNames) {
getEventProducers(instance, eventName).add(producer);
}
return {
async next() {
@ -101,7 +105,11 @@ function iterator(instance, eventName) {
async return(value) {
queue = undefined;
getEventProducers(instance, eventName).delete(producer);
for (const eventName of eventNames) {
getEventProducers(instance, eventName).delete(producer);
}
flush();
return arguments.length > 0 ?
@ -187,42 +195,52 @@ class Emittery {
producersMap.set(this, new Map());
}
on(eventName, listener) {
assertEventName(eventName);
assertListener(listener);
getListeners(this, eventName).add(listener);
if (!isListenerSymbol(eventName)) {
this.emit(listenerAdded, {eventName, listener});
}
return this.off.bind(this, eventName, listener);
}
off(eventName, listener) {
assertEventName(eventName);
on(eventNames, listener) {
assertListener(listener);
if (!isListenerSymbol(eventName)) {
this.emit(listenerRemoved, {eventName, listener});
}
getListeners(this, eventName).delete(listener);
}
once(eventName) {
return new Promise(resolve => {
eventNames = Array.isArray(eventNames) ? eventNames : [eventNames];
for (const eventName of eventNames) {
assertEventName(eventName);
const off = this.on(eventName, data => {
getListeners(this, eventName).add(listener);
if (!isListenerSymbol(eventName)) {
this.emit(listenerAdded, {eventName, listener});
}
}
return this.off.bind(this, eventNames, listener);
}
off(eventNames, listener) {
assertListener(listener);
eventNames = Array.isArray(eventNames) ? eventNames : [eventNames];
for (const eventName of eventNames) {
assertEventName(eventName);
getListeners(this, eventName).delete(listener);
if (!isListenerSymbol(eventName)) {
this.emit(listenerRemoved, {eventName, listener});
}
}
}
once(eventNames) {
return new Promise(resolve => {
const off = this.on(eventNames, data => {
off();
resolve(data);
});
});
}
events(eventName) {
assertEventName(eventName);
return iterator(this, eventName);
events(eventNames) {
eventNames = Array.isArray(eventNames) ? eventNames : [eventNames];
for (const eventName of eventNames) {
assertEventName(eventName);
}
return iterator(this, eventNames);
}
async emit(eventName, eventData) {
@ -236,7 +254,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);
@ -291,52 +309,62 @@ class Emittery {
anyMap.get(this).delete(listener);
}
clearListeners(eventName) {
if (typeof eventName === 'string') {
getListeners(this, eventName).clear();
clearListeners(eventNames) {
eventNames = Array.isArray(eventNames) ? eventNames : [eventNames];
const producers = getEventProducers(this, eventName);
for (const eventName of eventNames) {
if (typeof eventName === 'string' || typeof eventName === 'symbol') {
getListeners(this, eventName).clear();
for (const producer of producers) {
producer.finish();
}
const producers = getEventProducers(this, eventName);
producers.clear();
} else {
anyMap.get(this).clear();
for (const listeners of eventsMap.get(this).values()) {
listeners.clear();
}
for (const producers of producersMap.get(this).values()) {
for (const producer of producers) {
producer.finish();
}
producers.clear();
} else {
anyMap.get(this).clear();
for (const listeners of eventsMap.get(this).values()) {
listeners.clear();
}
for (const producers of producersMap.get(this).values()) {
for (const producer of producers) {
producer.finish();
}
producers.clear();
}
}
}
}
listenerCount(eventName) {
if (typeof eventName === 'string') {
return anyMap.get(this).size + getListeners(this, eventName).size +
getEventProducers(this, eventName).size + getEventProducers(this).size;
}
listenerCount(eventNames) {
eventNames = Array.isArray(eventNames) ? eventNames : [eventNames];
let count = 0;
if (typeof eventName !== 'undefined') {
assertEventName(eventName);
}
for (const eventName of eventNames) {
if (typeof eventName === 'string') {
count += anyMap.get(this).size + getListeners(this, eventName).size +
getEventProducers(this, eventName).size + getEventProducers(this).size;
continue;
}
let count = anyMap.get(this).size;
if (typeof eventName !== 'undefined') {
assertEventName(eventName);
}
for (const value of eventsMap.get(this).values()) {
count += value.size;
}
count += anyMap.get(this).size;
for (const value of producersMap.get(this).values()) {
count += value.size;
for (const value of eventsMap.get(this).values()) {
count += value.size;
}
for (const value of producersMap.get(this).values()) {
count += value.size;
}
}
return count;
@ -364,13 +392,6 @@ class Emittery {
const allEmitteryMethods = Object.getOwnPropertyNames(Emittery.prototype).filter(v => v !== 'constructor');
// Subclass used to encourage TS users to type their events.
Emittery.Typed = class extends Emittery {};
Object.defineProperty(Emittery.Typed, 'Typed', {
enumerable: false,
value: undefined
});
Object.defineProperty(Emittery, 'listenerAdded', {
value: listenerAdded,
writable: false,

7
node_modules/emittery/package.json generated vendored
View file

@ -1,6 +1,6 @@
{
"name": "emittery",
"version": "0.6.0",
"version": "0.8.1",
"description": "Simple and modern async event emitter",
"license": "MIT",
"repository": "sindresorhus/emittery",
@ -50,12 +50,11 @@
"devDependencies": {
"@types/node": "^13.7.5",
"ava": "^2.4.0",
"codecov": "^3.1.0",
"delay": "^4.3.0",
"nyc": "^15.0.0",
"p-event": "^4.1.0",
"tsd": "^0.11.0",
"xo": "^0.25.4"
"tsd": "^0.14.0",
"xo": "^0.36.1"
},
"nyc": {
"reporter": [

119
node_modules/emittery/readme.md generated vendored
View file

@ -2,7 +2,8 @@
> Simple and modern async event emitter
[![Build Status](https://travis-ci.org/sindresorhus/emittery.svg?branch=master)](https://travis-ci.org/sindresorhus/emittery) [![codecov](https://codecov.io/gh/sindresorhus/emittery/branch/master/graph/badge.svg)](https://codecov.io/gh/sindresorhus/emittery) [![](https://badgen.net/bundlephobia/minzip/emittery)](https://bundlephobia.com/result?p=emittery)
[![Coverage Status](https://codecov.io/gh/sindresorhus/emittery/branch/master/graph/badge.svg)](https://codecov.io/gh/sindresorhus/emittery)
[![](https://badgen.net/bundlephobia/minzip/emittery)](https://bundlephobia.com/result?p=emittery)
It works in Node.js and the browser (using a bundler).
@ -45,14 +46,30 @@ Symbol event names can be used to avoid name collisions when your classes are ex
### emitter = new Emittery()
#### on(eventName, listener)
#### on(eventName | eventName[], listener)
Subscribe to an event.
Subscribe to one or more events.
Returns an unsubscribe method.
Using the same listener multiple times for the same event will result in only one method call per emitted event.
```js
const Emittery = require('emittery');
const emitter = new Emittery();
emitter.on('🦄', data => {
console.log(data);
});
emitter.on(['🦄', '🐶'], data => {
console.log(data);
});
emitter.emit('🦄', '🌈'); // log => '🌈' x2
emitter.emit('🐶', '🍖'); // log => '🍖'
```
##### Custom subscribable events
Emittery exports some symbols which represent custom events that can be passed to `Emitter.on` and similar methods.
@ -87,15 +104,34 @@ Only events that are not of this type are able to trigger these events.
##### listener(data)
#### off(eventName, listener)
#### off(eventName | eventName[], listener)
Remove an event subscription.
Remove one or more event subscriptions.
```js
const Emittery = require('emittery');
const emitter = new Emittery();
const listener = data => console.log(data);
(async () => {
emitter.on(['🦄', '🐶', '🦊'], listener);
await emitter.emit('🦄', 'a');
await emitter.emit('🐶', 'b');
await emitter.emit('🦊', 'c');
emitter.off('🦄', listener);
emitter.off(['🐶', '🦊'], listener);
await emitter.emit('🦄', 'a'); // Nothing happens
await emitter.emit('🐶', 'b'); // Nothing happens
await emitter.emit('🦊', 'c'); // Nothing happens
})();
```
##### listener(data)
#### once(eventName)
#### once(eventName | eventName[])
Subscribe to an event only once. It will be unsubscribed after the first event.
Subscribe to one or more events only once. It will be unsubscribed after the first event.
Returns a promise for the event data when `eventName` is emitted.
@ -108,8 +144,12 @@ emitter.once('🦄').then(data => {
console.log(data);
//=> '🌈'
});
emitter.once(['🦄', '🐶']).then(data => {
console.log(data);
});
emitter.emit('🦄', '🌈');
emitter.emit('🦄', '🌈'); // Log => '🌈' x2
emitter.emit('🐶', '🍖'); // Nothing happens
```
#### events(eventName)
@ -164,6 +204,35 @@ for await (const data of iterator) {
}
```
It accepts multiple event names.
```js
const Emittery = require('emittery');
const emitter = new Emittery();
const iterator = emitter.events(['🦄', '🦊']);
emitter.emit('🦄', '🌈1'); // Buffered
emitter.emit('🦊', '🌈2'); // Buffered
iterator
.next()
.then(({value, done}) => {
// done === false
// value === '🌈1'
return iterator.next();
})
.then(({value, done}) => {
// done === false
// value === '🌈2'
// Revoke subscription
return iterator.return();
})
.then(({done}) => {
// done === true
});
```
#### emit(eventName, data?)
Trigger an event asynchronously, optionally with some data. Listeners are called in the order they were added, but executed concurrently.
@ -222,15 +291,15 @@ iterator.next()
In the same way as for `events`, you can subscribe by using the `for await` statement
#### clearListeners()
#### clearListeners(eventNames?)
Clear all event listeners on the instance.
If `eventName` is given, only the listeners for that event are cleared.
If `eventNames` is given, only the listeners for that events are cleared.
#### listenerCount(eventName?)
#### listenerCount(eventNames?)
The number of listeners for the `eventName` or all events if not specified.
The number of listeners for the `eventNames` or all events if not specified.
#### bindMethods(target, methodNames?)
@ -248,17 +317,31 @@ object.emit('event');
## TypeScript
The default `Emittery` class does not let you type allowed event names and their associated data. However, you can use `Emittery.Typed` with generics:
The default `Emittery` class has generic types that can be provided by TypeScript users to strongly type the list of events and the data passed to their event listeners.
```ts
import Emittery = require('emittery');
const emitter = new Emittery.Typed<{value: string}, 'open' | 'close'>();
const emitter = new Emittery<
// Pass `{[eventName]: undefined | <eventArg>}` as the first type argument for events that pass data to their listeners.
// A value of `undefined` in this map means the event listeners should expect no data, and a type other than `undefined` means the listeners will receive one argument of that type.
{
open: string,
close: undefined
}
>();
emitter.emit('open');
emitter.emit('value', 'foo\n');
emitter.emit('value', 1); // TS compilation error
emitter.emit('end'); // TS compilation error
// Typechecks just fine because the data type for the `open` event is `string`.
emitter.emit('open', 'foo\n');
// Typechecks just fine because `close` is present but points to undefined in the event data type map.
emitter.emit('close');
// TS compilation error because `1` isn't assignable to `string`.
emitter.emit('open', 1);
// TS compilation error because `other` isn't defined in the event data type map.
emitter.emit('other');
```
### Emittery.mixin(emitteryPropertyName, methodNames?)