Skip to content

Commit

Permalink
fix: fix type mismatch in NodeStyleEventEmitter (#3530)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
joemphilips authored and benlesh committed Apr 7, 2018
1 parent 32e7f75 commit 3f51ddd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/internal/observable/fromEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -193,8 +195,8 @@ function setupSubscription<T>(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');
}
Expand Down

0 comments on commit 3f51ddd

Please sign in to comment.