Skip to content

Commit

Permalink
fix: fix a typing mismatch in FromEventObservable (#3536)
Browse files Browse the repository at this point in the history
  • Loading branch information
joemphilips authored and benlesh committed May 4, 2018
1 parent 7b90063 commit 21a59a7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/observable/FromEventObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import { Subscriber } from '../Subscriber';
const toString: Function = Object.prototype.toString;

export type NodeStyleEventEmitter = {
addListener: (eventName: string, handler: Function) => void;
removeListener: (eventName: string, handler: Function) => void;
addListener: (eventName: string, handler: NodeEventHandler) => void;
removeListener: (eventName: string, handler: NodeEventHandler) => void;
};

export type NodeEventHandler = (...args: any[]) => void;

function isNodeStyleEventEmitter(sourceObj: any): sourceObj is NodeStyleEventEmitter {
return !!sourceObj && typeof sourceObj.addListener === 'function' && typeof sourceObj.removeListener === 'function';
}
Expand Down Expand Up @@ -213,8 +216,8 @@ export class FromEventObservable<T> extends Observable<T> {
unsubscribe = () => source.off(eventName, handler);
} else if (isNodeStyleEventEmitter(sourceObj)) {
const source = sourceObj;
sourceObj.addListener(eventName, handler);
unsubscribe = () => source.removeListener(eventName, handler);
sourceObj.addListener(eventName, handler as NodeEventHandler);
unsubscribe = () => source.removeListener(eventName, handler as NodeEventHandler);
} else {
throw new TypeError('Invalid event target');
}
Expand Down

0 comments on commit 21a59a7

Please sign in to comment.