Interface GenericEventEmitter<TEvent, TFunc>

A typed interface of EventEmitter.

Use the & operator to combine multiple event/function pairs into a single event emitter. The result needs to be a type and not an interface because of https://github.com/microsoft/TypeScript/issues/16936.

Use the createGenericEventEmitterClass function to generate an event emitter class with the correct typings in case EventEmitter needs to be extended.

Type Parameters

  • TEvent extends string | symbol

  • TFunc extends ((...args) => void)

Hierarchy

  • EventEmitter
    • GenericEventEmitter

Properties

addListener: ((event, listener) => GenericEventEmitter<TEvent, TFunc>)

Type declaration

emit: ((event, ...args) => boolean)

Type declaration

    • (event, ...args): boolean
    • Parameters

      • event: TEvent
      • Rest ...args: Parameters<TFunc>

      Returns boolean

eventNames: (() => TEvent[])

Type declaration

    • (): TEvent[]
    • Returns TEvent[]

listenerCount: ((event) => number)

Type declaration

    • (event): number
    • Parameters

      • event: TEvent

      Returns number

listeners: ((event) => TFunc[])

Type declaration

    • (event): TFunc[]
    • Parameters

      • event: TEvent

      Returns TFunc[]

off: ((event, listener) => GenericEventEmitter<TEvent, TFunc>)

Type declaration

on: ((event, listener) => GenericEventEmitter<TEvent, TFunc>)

Type declaration

once: ((event, listener) => GenericEventEmitter<TEvent, TFunc>)

Type declaration

prependListener: ((event, listener) => GenericEventEmitter<TEvent, TFunc>)

Type declaration

prependOnceListener: ((event, listener) => GenericEventEmitter<TEvent, TFunc>)

Type declaration

rawListeners: ((event) => TFunc[])

Type declaration

    • (event): TFunc[]
    • Parameters

      • event: TEvent

      Returns TFunc[]

removeAllListeners: ((event) => GenericEventEmitter<TEvent, TFunc>)

Type declaration

removeListener: ((event, listener) => GenericEventEmitter<TEvent, TFunc>)

Type declaration

Methods

  • Parameters

    • error: Error
    • event: string
    • Rest ...args: any[]

    Returns void

  • Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to defaultMaxListeners.

    Returns number

    Since

    v1.0.0

  • By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set toInfinity (or 0) to indicate an unlimited number of listeners.

    Returns a reference to the EventEmitter, so that calls can be chained.

    Parameters

    • n: number

    Returns GenericEventEmitter<TEvent, TFunc>

    Since

    v0.3.5