microsoft / microsoft/TypeScript

window.parent should have the same global variables as window

Open
#41,684 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Domain: lib.d.ts Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript Playground and inspect the DOM typings related to window.parent, Window, and globalThis. Reproduce the reported error, then verify that window.parent exposes the same base globals as window, including HTMLDivElement and Element.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.