BramComyn / safeguard-fetch

0 stars 0 forks source link

Add Generic ClientEventEmitter type and it's implemented types as suggested #43 #46

Closed BramComyn closed 1 month ago

BramComyn commented 1 month ago

Feature description

I quote:

Something like

 export type ClientEventEmitter<E> = EventEmitter && {
  on(event: E, listener: ClientEventHandler<E>): this;
   on(event: string, listener: Function): this;
};

such that you can

 export type PingEventEmitter = ClientEventEmitter<'ping'>;

and perhaps also extend the definition to also support arrays such that the following are equivalent:

type X = ClientEventEmitter<'ping'> | ClientEventEmitter<'pong'> | ClientEventEmitter<'stream'>;
type Y = ClientEventEmitter<['ping', 'pong', 'stream']>;

As well as this example.