microsoft / microsoft/TypeScript

window.parent should have the same global variables as window

Offen
#41,684 4 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Domain: lib.d.ts Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem verlinkten TypeScript Playground und untersuche die DOM-Typings im Zusammenhang mit window.parent, Window und globalThis. Reproduziere den gemeldeten Fehler und überprüfe anschließend, dass window.parent dieselben grundlegenden Globals wie window bereitstellt, einschließlich HTMLDivElement und Element.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers, web-dev
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.