microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

Home Page:https://www.typescriptlang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`window.parent` should be nullable

yohabe opened this issue · comments

⚙ Compilation target

es2017

⚙ Library

ESNext

Missing / Incorrect Definition

In the whatwg definition, window.parent is nullable. whatwg/html#2123

The definition of window.parent in this repository is not nullable.

readonly parent: WindowProxy;

https://github.com/microsoft/TypeScript/blob/b9c71c3fc39f7cbafa82f8aa6f1d3b8a86e27ede/src/lib/dom.generated.d.ts#L26013-L26020

BTW, the definition of window.top is nullable, which is inconsistent.

 readonly top: WindowProxy | null;

https://github.com/microsoft/TypeScript/blob/b9c71c3fc39f7cbafa82f8aa6f1d3b8a86e27ede/src/lib/dom.generated.d.ts#L26069-L26070

Sample Code

readonly parent: WindowProxy;

Documentation Link

https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-window-object

@whzx5byb
Thank you for your response.

Wouldn't it be better for consistency to make window.top non-nullable?

Which one is this bug about?

There are three options.

Option 1: Comply with WHATWG by making window.parent nullable.

Option 2: Given that window.parent is non-nullable as TypeScript's specification, make window.top also non-nullable for consistency.

Option 3: Leave it as is, meaning window.parent is non-nullable and window.top is nullable. The inconsistency is attributed to TypeScript's specification.

Without a stronger argument for any one of those, we'll leave as-is. Thanks!

@RyanCavanaugh

What is the reason for creating a situation that contradicts the WHATWG specifications and lacks consistency with the definition of window.top?