You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
window.removeEventListener needs specialized signatures like addEventListener #3871
changed the title [-]window.removeEventListener needs a more accurate type definition[/-][+]window.removeEventListener needs specialized signatures like addEventListener[/+]on Jul 15, 2015
The reason addEventListener has these overloads is to allow for flowing contextual type to the event handler. but in the remove case, why would pass a lambda? LilRed can you share a sample where this is useful in removeEventListener
function foo(bar: StorageEvent) { console.log("foo!") };
window.addEventListener("storage", foo); //event handler is registered
window.removeEventListener("storage", foo); //back to normal
:) i understand. i was talking about the contextual type. contextual types are what allows you to get type of a lambda paramter e.g.:
window.addEventListener("storage",(e)=>{e;// <- e is StorageEvent becuase contextual type flowed from the definition of window.addEventListener("storage", ...);})
so it seems the scenario you are talking about is:
functionfoo(bar: StorageEvent){console.log("foo!")};window.removeEventListener("click",foo);// Error MouseEventListener is not assignable to StorageEventListener
is this correct? if so there is a different problem that would make this not work, once #1003 is fixed we can revisit this.
as mentioned earlier in my reply, this does not seem to be of much value as the event is usually defined in the addEventListener method. please reopen if this is not the case.
I'm using typescript with ionic 1.0 & cordova and bumping against this error:
TypeScript error: typings/globals/InAppBrowser/index.d.ts(46,11): Error TS2430: Interface 'InAppBrowser' incorrectly extends interface 'Window'.
Types of property 'addEventListener' are incompatible.
Type '{ (type: "loadstart", callback: (event: InAppBrowserEvent) => void): void; (type: "loadstop", cal...' is not assignable to type '{ (type: "MSGestureChange", listener: (this: this, ev: MSGestureEvent) => any, useCapture?: boole...'.
Types of parameters 'type' and 'type' are incompatible.
Type '"MSGestureChange"' is not assignable to type '"loadstart"'.
with:
$ tsc --version
Version 2.0.6
What is the problem here and how to solve it? Thanks for any advice.
looks like InAppBrowser does not include all overloads for addEventListener which makes the class/interface not implement the Window interface correctly. the fix would be done on the declaration file i would say.
Activity
danquirk commentedon Jul 15, 2015
Which version of lib.d.ts are you looking at? They appear the same in the latest bits
carlpaten commentedon Jul 15, 2015
Version isn't clear, but there's this bit:
danquirk commentedon Jul 15, 2015
Ah, I see, you mean you want all those specialized signatures for removeEventListener.
[-]window.removeEventListener needs a more accurate type definition[/-][+]window.removeEventListener needs specialized signatures like addEventListener[/+]mhegazy commentedon Jul 16, 2015
The reason addEventListener has these overloads is to allow for flowing contextual type to the event handler. but in the remove case, why would pass a lambda? LilRed can you share a sample where this is useful in removeEventListener
carlpaten commentedon Jul 18, 2015
You call removeEventListener with a reference to the lambda you called
addEventListener with.
mhegazy commentedon Jul 20, 2015
:) i understand. i was talking about the contextual type. contextual types are what allows you to get type of a lambda paramter e.g.:
so it seems the scenario you are talking about is:
is this correct? if so there is a different problem that would make this not work, once #1003 is fixed we can revisit this.
mhegazy commentedon Feb 22, 2016
as mentioned earlier in my reply, this does not seem to be of much value as the event is usually defined in the
addEventListenermethod. please reopen if this is not the case.MaxDaten commentedon Nov 8, 2016
Hi,
I'm using typescript with ionic 1.0 & cordova and bumping against this error:
with:
What is the problem here and how to solve it? Thanks for any advice.
mhegazy commentedon Nov 8, 2016
looks like
InAppBrowserdoes not include all overloads foraddEventListenerwhich makes the class/interface not implement theWindowinterface correctly. the fix would be done on the declaration file i would say.//cc Michael Braude (@mbraude)