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

  • Returns number

  • Parameters

    • n: number

    Returns GenericEventEmitter<TEvent, TFunc>