index.d.ts 1.4 KB

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