From 3f51dddbe8cdf6a36b5938918c5bfd7ba42a6872 Mon Sep 17 00:00:00 2001 From: Joe Miyamoto Date: Sat, 7 Apr 2018 13:24:51 +0900 Subject: [PATCH] fix: fix type mismatch in NodeStyleEventEmitter (#3530) * change `type` to `interface` since type does not allow returning this * define its own type for handler in NodeStyleEventEmitter * cast handler to NodeEventHandler when adding a listener to sourceObj --- src/internal/observable/fromEvent.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/internal/observable/fromEvent.ts b/src/internal/observable/fromEvent.ts index 66acc7fd5c..e1d0e3fc72 100644 --- a/src/internal/observable/fromEvent.ts +++ b/src/internal/observable/fromEvent.ts @@ -6,10 +6,12 @@ import { map } from '../operators/map'; const toString: Function = Object.prototype.toString; -export type NodeStyleEventEmitter = { - addListener: (eventName: string, handler: Function) => void; - removeListener: (eventName: string, handler: Function) => void; -}; +export interface NodeStyleEventEmitter { + addListener: (eventName: string | symbol, handler: NodeEventHandler) => this; + removeListener: (eventName: string | symbol, handler: NodeEventHandler) => this; +} + +export type NodeEventHandler = (...args: any[]) => void; export type JQueryStyleEventEmitter = { on: (eventName: string, handler: Function) => void; @@ -193,8 +195,8 @@ function setupSubscription(sourceObj: EventTargetLike, eventName: string, 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'); }