microsoft / microsoft/TypeScript
Type the tagName string property of Element derivations to aid overloading and for discriminated unions
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Search Terms
tagName, nodeName
Suggestion
Typing the tagName property in lib.dom.d.ts for Element and derivations ( or only concrete derivations and a discriminated type alias of these )
e.g
interface SVGGElement extends SVGGraphicsElement {
//..existing definition
tagName:"g"
}
Use Cases
Simpler to write overloads, overloaded by single argument type ( order does not matter )
Discriminated Unions
Examples
interface SVGCircleElement{
tagName:"circle"
}
interface SVGGElement{
tagName:"g"
}
interface SVGRectElement{
tagName:"rect"
}
Without above order matters with overload
adopt(node: SVGGElement): G;//issue with this before circle overload
adopt(node: SVGCircleElement): Circle;
With above and
type SVGTestUnionType=SVGCircleElement|SVGRectElement;
function(circleOrG:SVGTestUnionType){
switch(circleOrG.tagName){
case "circle":
//circle members available
break;
case "rect":
//rect members available
break;
}
}
Checklist
My suggestion meets these guidelines: YES
- This wouldn't be a breaking change in existing TypeScript / JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. new expression-level syntax)
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 in lib.dom.d.ts and review the Element hierarchy and concrete SVG element declarations mentioned in the issue. Determine the intended scope for literal tagName types and how the declarations should support overloads and discriminated unions. Done means the relevant declarations provide the requested narrowing without changing runtime JavaScript behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100