Skip to content

Commit

Permalink
[ts] Fix TypeScript type definitions (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
aoberoi authored and lpinca committed Feb 7, 2018
1 parent 5aa0329 commit 7b2f6d0
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
export as namespace EventEmitter;

type ListenerFn = (...args: Array<any>) => void;

/**
* Minimal `EventEmitter` interface that is molded against the Node.js
* `EventEmitter` interface.
*/
export class EventEmitter {
declare class EventEmitter {
static prefixed: string | boolean;

/**
Expand All @@ -18,7 +14,7 @@ export class EventEmitter {
/**
* Return the listeners registered for a given event.
*/
listeners(event: string | symbol): Array<ListenerFn>;
listeners(event: string | symbol): Array<EventEmitter.ListenerFn>;

/**
* Return the number of listeners listening to a given event.
Expand All @@ -33,22 +29,36 @@ export class EventEmitter {
/**
* Add a listener for a given event.
*/
on(event: string | symbol, fn: ListenerFn, context?: any): this;
addListener(event: string | symbol, fn: ListenerFn, context?: any): this;
on(event: string | symbol, fn: EventEmitter.ListenerFn, context?: any): this;
addListener(event: string | symbol, fn: EventEmitter.ListenerFn, context?: any): this;

/**
* Add a one-time listener for a given event.
*/
once(event: string | symbol, fn: ListenerFn, context?: any): this;
once(event: string | symbol, fn: EventEmitter.ListenerFn, context?: any): this;

/**
* Remove the listeners of a given event.
*/
removeListener(event: string | symbol, fn?: ListenerFn, context?: any, once?: boolean): this;
off(event: string | symbol, fn?: ListenerFn, context?: any, once?: boolean): this;
removeListener(event: string | symbol, fn?: EventEmitter.ListenerFn, context?: any, once?: boolean): this;
off(event: string | symbol, fn?: EventEmitter.ListenerFn, context?: any, once?: boolean): this;

/**
* Remove all listeners, or those of the specified event.
*/
removeAllListeners(event?: string | symbol): this;
}

declare namespace EventEmitter {
export interface ListenerFn {
(...args: Array<any>): void;
}

export interface EventEmitterStatic {
new(): EventEmitter;
}

export const EventEmitter: EventEmitterStatic;
}

export = EventEmitter;

0 comments on commit 7b2f6d0

Please sign in to comment.