-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EventListener interface does not accept objects with a handleEvent method #1224
Comments
http://www.w3.org/TR/DOM-Level-3-Events/#widl-EventListener-handleEvent
I think EventListener interface should be changed to: interface EventListener {
handleEvent(evt: Event): void;
}
// OR
type EventListener = { handleEvent(evt: Event): void } | Function; and EventTarget interface should be changed to: interface EventTarget {
removeEventListener(type: string, listener: Function|EventListener, useCapture?: boolean): void;
addEventListener(type: string, listener: Function|EventListener, useCapture?: boolean): void;
dispatchEvent(evt: Event): boolean;
} I also think #299 is somewhat related. |
@mhegazy how was this ticket resolved? I hit this issue today when |
here is what we have in interface EventListener {
(evt: Event): void;
}
interface EventListenerObject {
handleEvent(evt: Event): void;
}
declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
interface EventTarget {
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
dispatchEvent(evt: Event): boolean;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
} this means that the assigning anything with a call signature works: var e: EventTarget;
var f: () => void;
e.addEventListener("e", f);
e.removeEventListener("e", f); the issue is that var e: EventTarget;
var f: Function;
e.addEventListener("e", f); // error
e.removeEventListener("e", f); // error which is similar to: var f1: () => void;
var f2: Function;
f1 = f2; // Error
f2 = f1; // OK Now the question is do we need the |
It would be neat if the following worked: const styleSheetLoad = (link: HTMLLinkElement): Promise<void> =>
new Promise(resolve => {
link.addEventListener('load', resolve);
}); Instead I get:
But perhaps I'm just doing it wrong. |
Issue from the old tracker:
https://typescript.codeplex.com/workitem/45
EventTarget.addEventListener accepts a function or an object implementing EventListener:
https://developer.mozilla.org/en-US/docs/Web/API/EventListener
The text was updated successfully, but these errors were encountered: