microsoft / microsoft/TypeScript

HTMLCollection should be string indexable

Open
#19,437 5 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Domain: lib.d.ts Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

According to MDN, HTMLCollection should be string indexable:

HTMLCollection also exposes its members directly as properties by both name and index. HTML IDs may contain : and . as valid characters, which would necessitate using bracket notation for property access. Currently HTMLCollections does not recognize purely numeric IDs, which would cause conflict with the array-style access, though HTML5 does permit these.

TypeScript Version: master

Code

declare const elements: HTMLCollection;
elements['myId'] // implicit any error, where it should be the same type as elements[0].

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the HTMLCollection declaration in TypeScript's standard library definitions and compare its numeric and named property access. Use the issue's code example to verify that string indexing produces the same element type as numeric indexing; done means the purely named access no longer reports an implicit any error.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, typescript
Domain
web-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.