diff --git a/index.d.ts b/index.d.ts index d18212c..a443eef 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,6 +2,8 @@ export type EventMap = { [key: string]: (...args: any[]) => void } +type KeyOf = keyof T | `${Extract}` | (Extract extends never ? never : number); + /** * Type-safe event emitter. * @@ -19,22 +21,22 @@ export type EventMap = { * ``` */ interface TypedEventEmitter { - addListener (event: E, listener: Events[E]): this - on (event: E, listener: Events[E]): this - once (event: E, listener: Events[E]): this - prependListener (event: E, listener: Events[E]): this - prependOnceListener (event: E, listener: Events[E]): this + addListener> (event: E, listener: Events[E]): this + on> (event: E, listener: Events[E]): this + once> (event: E, listener: Events[E]): this + prependListener> (event: E, listener: Events[E]): this + prependOnceListener> (event: E, listener: Events[E]): this - off(event: E, listener: Events[E]): this - removeAllListeners (event?: E): this - removeListener (event: E, listener: Events[E]): this + off>(event: E, listener: Events[E]): this + removeAllListeners> (event?: E): this + removeListener> (event: E, listener: Events[E]): this - emit (event: E, ...args: Parameters): boolean + emit> (event: E, ...args: Parameters): boolean // The sloppy `eventNames()` return type is to mitigate type incompatibilities - see #5 - eventNames (): (keyof Events | string | symbol)[] - rawListeners (event: E): Events[E][] - listeners (event: E): Events[E][] - listenerCount (event: E): number + eventNames (): (KeyOf | string | symbol)[] + rawListeners> (event: E): Events[E][] + listeners> (event: E): Events[E][] + listenerCount> (event: E): number getMaxListeners (): number setMaxListeners (maxListeners: number): this