TypeScript Version: 4.1.2
Search Terms: window.parent, window.Element, globalThis
Code
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.
Playground Link: https://www.typescriptlang.org/play?#code/O4SwdgJg9sB0ASAVAsgGQCIgG4FEA2ApgLYFgAuA3AFCiQywAOAhgE6lkIobb7HsVA
TypeScript Version: 4.1.2
Search Terms:
window.parent,window.Element,globalThisCode
Expected behavior:
The
window.parentobject should have the same base global variables as thewindowobject. If not in the context of iframe, thenwindow === window.parentso all global variables should be the same in such a case. When being in the iframe contextwindow !== window.parenthowever it should still have all the base global variables, so that we can do for exampleelement instanceof window.parent.Element. You could think, why don't just writeelement 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 sowindow.parent.Element !== window.Element. In TS all the global variables are defined in theglobalThisso the type for thewindow.parentshould bedeclare var parent: Window & typeof globalThis;Actual behavior:
The
window.parent.HTMLDivElement;does not exist on type Window.Playground Link: https://www.typescriptlang.org/play?#code/O4SwdgJg9sB0ASAVAsgGQCIgG4FEA2ApgLYFgAuA3AFCiQywAOAhgE6lkIobb7HsVA