Title: NodeList, NodeListOf
Open Graph Title: NodeList, NodeListOf
X Title: NodeList, NodeListOf
Description: Currently, the following DOM methods has a return type definition of NodeList, but the type of nodes returned is actually always Element: getElementsByClassName getElementsByTagNameNS getElementsByTagName(name: string) getElementsByName ...
Open Graph Description: Currently, the following DOM methods has a return type definition of NodeList, but the type of nodes returned is actually always Element: getElementsByClassName getElementsByTagNameNS getElementsBy...
X Description: Currently, the following DOM methods has a return type definition of NodeList, but the type of nodes returned is actually always Element: getElementsByClassName getElementsByTagNameNS getElementsBy...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/424
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"NodeList, NodeListOf\u003cElement> and HTMLCollection","articleBody":"Currently, the following DOM methods has a return type definition of \u003ccode>NodeList\u003c/code>, but the type of nodes returned is actually always \u003ccode>Element\u003c/code>:\n\n\u003ccode>getElementsByClassName\u003c/code>\n\u003ccode>getElementsByTagNameNS\u003c/code>\n\u003ccode>getElementsByTagName(name: string)\u003c/code>\n\u003ccode>getElementsByName\u003c/code>\n\u003ccode>msElementsFromPoint\u003c/code>\n\u003ccode>msElementsFromRect\u003c/code>\n\nAs a result, a cast to \u003ccode>Element\u003c/code> is required before any method of \u003ccode>Element\u003c/code> can be used. To remove the need of the cast, I suggest changing their return type definition to \u003ccode>NodeListOf<Element>\u003c/code>.\n\nAlso, there are some HTML DOM properties (e.g. \u003ccode>document.forms\u003c/code>) having a return type definition of \u003ccode>HTMLCollection\u003c/code>, but \u003ccode>HTMLCollection\u003c/code> does not extend \u003ccode>NodeListOf<HTMLElement>\u003c/code>. That leads to some difficulties in creating a method that takes a list of elements. I suggest changing \u003ccode>HTMLCollection\u003c/code> to extend \u003ccode>NodeListOf<HTMLElement>\u003c/code>.\n\nFinally, should a \u003ccode>List<T>\u003c/code> interface with the following definition be created, such that \u003ccode>Array<T>\u003c/code>, \u003ccode>NodeList\u003c/code>, \u003ccode>NodeListOf<HTMLElement>\u003c/code> and \u003ccode>HTMLCollection\u003c/code> all extend to \u003ccode>List<T>\u003c/code>?\n\n\u003cpre>\u003ccode>interface List\u003cT> {\n length: number;\n [index: number]: T;\n}\u003c/code>\u003c/pre>\n","author":{"url":"https://github.com/FranklinWhale","@type":"Person","name":"FranklinWhale"},"datePublished":"2014-08-11T12:26:12Z","url":"https://github.com/microsoft/TypeScript/issues/424"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2821ca40-0ebe-4509-b546-075e3b72682e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BCD2:2E7EBB:CA4F66:1008515:6B00FCFC |
| html-safe-nonce | a08fe4bf8c632c8d42fa3654fc5569d94d27155d8b877a1bad7620e31b511ed2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0QyOjJFN0VCQjpDQTRGNjY6MTAwODUxNTo2QjAwRkNGQyIsInZpc2l0b3JfaWQiOiIxMDUwMTkwOTA0MTgwNzI4MjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 468f57f9232bf2736b265b1f0cccf6e35dbb35d82c0460ead0f7227466493593 |
| hovercard-subject-tag | issue:39953149 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/424/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eb0086de69521a08e7dd4c5e82f13fe77f0ccffd676793a271b52e964cf54968/microsoft/TypeScript/issues/424 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eb0086de69521a08e7dd4c5e82f13fe77f0ccffd676793a271b52e964cf54968/microsoft/TypeScript/issues/424 |
| og:image:alt | Currently, the following DOM methods has a return type definition of NodeList, but the type of nodes returned is actually always Element: getElementsByClassName getElementsByTagNameNS getElementsBy... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | FranklinWhale |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width