-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
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