index.d.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Minimal `EventEmitter` interface that is molded against the Node.js
  3. * `EventEmitter` interface.
  4. */
  5. declare class EventEmitter<EventTypes extends string | symbol = string | symbol> {
  6. static prefixed: string | boolean;
  7. /**
  8. * Return an array listing the events for which the emitter has registered
  9. * listeners.
  10. */
  11. eventNames(): Array<EventTypes>;
  12. /**
  13. * Return the listeners registered for a given event.
  14. */
  15. listeners(event: EventTypes): Array<EventEmitter.ListenerFn>;
  16. /**
  17. * Return the number of listeners listening to a given event.
  18. */
  19. listenerCount(event: EventTypes): number;
  20. /**
  21. * Calls each of the listeners registered for a given event.
  22. */
  23. emit(event: EventTypes, ...args: Array<any>): boolean;
  24. /**
  25. * Add a listener for a given event.
  26. */
  27. on(event: EventTypes, fn: EventEmitter.ListenerFn, context?: any): this;
  28. addListener(event: EventTypes, fn: EventEmitter.ListenerFn, context?: any): this;
  29. /**
  30. * Add a one-time listener for a given event.
  31. */
  32. once(event: EventTypes, fn: EventEmitter.ListenerFn, context?: any): this;
  33. /**
  34. * Remove the listeners of a given event.
  35. */
  36. removeListener(event: EventTypes, fn?: EventEmitter.ListenerFn, context?: any, once?: boolean): this;
  37. off(event: EventTypes, fn?: EventEmitter.ListenerFn, context?: any, once?: boolean): this;
  38. /**
  39. * Remove all listeners, or those of the specified event.
  40. */
  41. removeAllListeners(event?: EventTypes): this;
  42. }
  43. declare namespace EventEmitter {
  44. export interface ListenerFn {
  45. (...args: Array<any>): void;
  46. }
  47. export interface EventEmitterStatic {
  48. new<EventTypes extends string | symbol = string | symbol>(): EventEmitter<EventTypes>;
  49. }
  50. export const EventEmitter: EventEmitterStatic;
  51. }
  52. export = EventEmitter;