gcedo / eventsourcemock

Mock EventSource in tests.
MIT License
30 stars 14 forks source link

Feature request: TypeScript Support #8

Open leonheess opened 1 year ago

leonheess commented 1 year ago

:)

challet commented 3 weeks ago

That may help

/* eventsourcemock.d.ts */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unsafe-function-type */

declare module "eventsourcemock" {
  type EventSourceConfigurationType = {
    withCredentials: boolean
  };
  type ReadyStateType = 0 | 1 | 2;

  export default class EventSource {
    constructor(url: string, configuration?: EventSourceConfigurationType): EventSource;
    addEventListener(eventName: string, listener: Function): void;
    removeEventListener(eventName: string, listener: Function): void;
    close(): void;
    emit(eventName: string, messageEvent?: MessageEvent): void;
    emitError(error: any): void;
    emitOpen(): void;
    emitMessage(message: any): void;
  }
  export const sources: { [key: string]: EventSource };
}