[Web API type definition issue] incorrect type definition for `getElementById()`
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- typescript
- Lĩnh vực
- tooling
Hướng nghiên cứu
Bắt đầu với các định nghĩa lib.dom được生成 cho Document và DocumentFragment, rồi lần theo cách các chữ ký getElementById của chúng được tạo ra. Xác nhận hành vi của Web API được thể hiện trong issue, cập nhật cả hai kiểu trả về thành Element | null và kiểm tra rằng các định nghĩa được tạo ra hoặc các kiểm tra liên quan phản ánh các chữ ký đã được sửa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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;
}
- Ngôn ngữ chính
- TypeScript
- Star
- 740
- Fork
- 474
- Merge trung bình
- 2 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 15
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/TypeScript-DOM-lib-generator
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
microsoft/TypeScript-DOM-lib-generator#2554 · 6 bình luận ·
-
lib.d.ts bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
lib.d.ts bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
microsoft/TypeScript-DOM-lib-generator#2154 · 1 reaction ·
-
lib.d.ts bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
microsoft/TypeScript-DOM-lib-generator#2107 · 5 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
microsoft/TypeScript-DOM-lib-generator#1675 · 2 bình luận · 1 reaction ·
Tất cả issue của microsoft/TypeScript-DOM-lib-generator
Issue tương tự
-
bug(cli): hapi doctor inline-media prints a fabricated B:\ helper-script path in packaged installs Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Crush Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
catppuccin/catppuccin#3125 ·
-
Add a SECURITY.md Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
ElementsProject/cln-application#167 · 1 bình luận · 1 reaction ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Quantco/pnpm-licenses#17 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100