microsoft / microsoft/TypeScript
Define 'tagName' values in Element interfaces to prevent misleading type acceptance.
Open
Nobody has claimed this yet.
Awaiting More Feedback
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🔎 Search Terms
- HTML Element Interfaces
- Element tagName
- Element Interfaces
- Incorrect element types accepted
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Element interfaces
⏯ Playground Link
Playground link with relevant code
💻 Code
// Elements can be assigned to variables of other element types because of interface overlaps being sufficient.
let element: HTMLSpanElement = document.createElement("div");
// If the interfaces included the appropriate 'tagName' property this could be avoided...
let spanElement: HTMLSpanElement & { tagName: "SPAN" } = document.createElement("div") as HTMLDivElement & { tagName: "DIV" };
🙁 Actual behavior
e.g. 'HTMLDivElement' instance can be assigned to variables of type 'HTMLSpanElement'.
🙂 Expected behavior
This should fail the type checking to avoid accidentally assigning elements of an incorrect type.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground reproduction and inspect the HTML Element interfaces involved, especially tagName on HTMLSpanElement and HTMLDivElement. Done means an HTMLDivElement is no longer accepted as an HTMLSpanElement, while the shown tagName intersection behavior remains represented accurately.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100