[Web API type definition issue] incorrect type definition for `getElementById()`
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- typescript
- 領域
- tooling
調査の方向性
Document と DocumentFragment の生成された lib.dom 定義から始め、それらの getElementById シグネチャがどのように生成されるかを追跡します。Issue に示されている Web API の動作を確認し、両方の戻り値の型を Element | null に更新して、生成された定義または関連するチェックに修正後のシグネチャが反映されていることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Summary
incorrect type definition for document.getElementById() and shadowRoot.getElementById()
Expected vs. Actual Behavior
The type definition in lib.dom shows the signature as:
interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEventHandlers, NonElementParentNode, ParentNode, XPathEvaluatorBase {
// ... omitted ...
getElementById(elementId: string): HTMLElement | null;
// ... omitted ...
}
The signature should be
interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEventHandlers, NonElementParentNode, ParentNode, XPathEvaluatorBase {
// ... omitted ...
getElementById(elementId: string): Element | null;
// ... omitted ...
}
Playground Link
Browser Support
- This API is supported in at least two major browser engines (not two Chromium-based browsers).
Have Tried The Latest Releases
- This issue applies to the latest release of TypeScript.
- This issue applies to the latest release of
@types/web.
Additional Context
Proof:
// Run this in your console:
document.body.innerHTML = '<svg><g id="foo"></g></svg>'
const g = document.body!.firstElementChild!.firstElementChild
console.log(g instanceof SVGGElement) // true
const g2 = document.getElementById('foo')
console.log(g2 instanceof SVGGElement) // still true (getElementById did not return HTMLElement | null)
The type is also wrong for other types of documents:
interface DocumentFragment extends Node, NonElementParentNode, ParentNode {
readonly ownerDocument: Document;
getElementById(elementId: string): HTMLElement | null;
}
- 主要言語
- TypeScript
- スター
- 740
- フォーク
- 474
- 平均マージ
- 2日 8時間
- マージ済み PR(30日)
- 15
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/TypeScript-DOM-lib-generator のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
microsoft/TypeScript-DOM-lib-generator#2554 · コメント 6 件 ·
-
lib.d.ts bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
lib.d.ts bug
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
microsoft/TypeScript-DOM-lib-generator#2154 · リアクション 1 件 ·
-
lib.d.ts bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
microsoft/TypeScript-DOM-lib-generator#2107 · コメント 5 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
microsoft/TypeScript-DOM-lib-generator#1675 · コメント 2 件 · リアクション 1 件 ·
microsoft/TypeScript-DOM-lib-generator の issue をすべて見る
似ている issue
-
bug(cli): hapi doctor inline-media prints a fabricated B:\ helper-script path in packaged installs オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
Crush オープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
catppuccin/catppuccin#3125 ·
-
Add a SECURITY.md オープン
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
ElementsProject/cln-application#167 · コメント 1 件 · リアクション 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Quantco/pnpm-licenses#17 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100