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.parent should have the same global variables as window #41684
window.HTMLDivElement;window.parent.HTMLDivElement;// Error here
Expected behavior:
The window.parent object should have the same base global variables as the window object. If not in the context of iframe, then window === window.parent so all global variables should be the same in such a case. When being in the iframe context window !== window.parent however it should still have all the base global variables, so that we can do for example element instanceof window.parent.Element. You could think, why don't just write element instanceof Element? The answer is that it would work in almost all browsers beside Chrome. And Chrome is actually the one implementing it correctly. Both global window and iframe window have their own global context so window.parent.Element !== window.Element. In TS all the global variables are defined in the globalThis so the type for the window.parent should be declare var parent: Window & typeof globalThis;
Actual behavior:
The window.parent.HTMLDivElement; does not exist on type Window.
The problem is that then you go too far in the opposite direction; globalThis can easily contain things that wouldn’t be shared between an iframe and its parent. Suppose this script ran in an iframe?
I see your point. My solution was just a quick guess just by looking how the window object is typed. I didn't know how the globalThis works. My point is just that window.parent should have all the base global variables. Maybe the solution would be to define them in some interface and extend it by both window and window.parent. Or maybe actually put them in the Window interface?
Activity
andrewbranch commentedon Nov 25, 2020
The problem is that then you go too far in the opposite direction;
globalThiscan easily contain things that wouldn’t be shared between an iframe and its parent. Suppose this script ran in an iframe?lukejagodzinski commentedon Nov 26, 2020
I see your point. My solution was just a quick guess just by looking how the window object is typed. I didn't know how the
globalThisworks. My point is just thatwindow.parentshould have all the base global variables. Maybe the solution would be to define them in some interface and extend it by bothwindowandwindow.parent. Or maybe actually put them in theWindowinterface?HolgerJeromin commentedon Aug 19, 2022
Same with
UIEvent.prototype.viewFor
Document.defaultViewwe had this PR which has the same problem as Andrew Branch (@andrewbranch) wrote:microsoft/TypeScript-DOM-lib-generator#820 (added
& typeof globalThis)eps1lon commentedon Aug 19, 2022
Yeah I see now how this overshot. But
defaultViewnot havingHTMLInputElementwas also annoying.