Microsoft/TypeScript

Inconsistent types between Document scrollingElement and documentElement

Open

#60,838 创建于 2024年12月22日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)TypeScript (6,726 fork)batch import
BugDomain: lib.d.tsHelp Wanted

仓库指标

Star
 (48,455 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 9 个 PR)

描述

🔎 Search Terms

I think document.scrollingElement should be of type Document["documentElement"] | null instead of Element | null. The spec (e.g. this and this) says that in standards mode scrollingElement returns the document root, which is document.documentElement and in quirks mode returns document.body or null.

document.body is always HTMLElement (right?) In principle, document.documentElement does not have to be HTMLElement (and there's an open issue about this, #29052, but currently Document.documentElement is still defined as HTMLElement, for some reason. So how come document.scrollingElement is not HTMLElement | null?

🕗 Version & Regression Information

N/A

⏯ Playground Link

No response

💻 Code

// Your code here

🙁 Actual behavior

document.scrollingElement is of type Element | null whereas document.documentElement and document.body are both of type HTMLElement.

🙂 Expected behavior

The non-null part of document.scrollingElement should be the same type as document.documentElement, which technically should be Element, but if document.documentElement is left as HTMLElement, as is currently, then document.scrollingElement should also be this.

Additional information about the issue

No response

贡献者指南