From 21a59a74e439fbb97e74da23b96f6e6e60f72814 Mon Sep 17 00:00:00 2001 From: Joe Miyamoto Date: Sat, 5 May 2018 04:01:28 +0900 Subject: [PATCH] fix: fix a typing mismatch in FromEventObservable (#3536) --- src/observable/FromEventObservable.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/observable/FromEventObservable.ts b/src/observable/FromEventObservable.ts index bae3bc8ac5..4705aafd24 100644 --- a/src/observable/FromEventObservable.ts +++ b/src/observable/FromEventObservable.ts @@ -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'; } @@ -213,8 +216,8 @@ export class FromEventObservable extends Observable { 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'); }