microsoft / microsoft/TypeScript

window.parent should have the same global variables as window

オープン
#41,684 コメント 4 件 リアクション 3 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Domain: lib.d.ts Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされている TypeScript Playground から始め、window.parent、Window、globalThis に関連する DOM の型定義を調べてください。報告されたエラーを再現し、window.parent が HTMLDivElement や Element を含め、window と同じ基本グローバルを公開していることを確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers, web-dev
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。