TypeScript-DOM-lib-generator
TypeScript-DOM-lib-generator copied to clipboard
Adjust `.parentElement` type to include `SVGElement`
In reality, this also includes | null but this has been removed in https://github.com/microsoft/TypeScript-DOM-lib-generator/commit/2cd8ad3974b63affd454164028960821e77a2e17 so I guess you want to omit that for pragmatic reasons.
Originally this was typed as Element | null (and that probably was the most "correct" type) but that was changed to HTMLELement | null here: https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/560 . However, SVGElement can appear here in a lot of scenarios.
An HTML element can be a parent of SVG (the simplest <div><svg/></div>), SVG element can be a parent of another SVG element (<svg><rect/></svg>) but also the SVG element can be a parent of an HTML element (<svg><foreignObject><div></div></foreignObject></svg>)
Thanks for the PR!
This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged.
Build has failed because you missed to include the generated files.
But did you considered the feedback from #1151 ?
Sorry, I've missed that discussion. I see the points raised there but having to cast this through unknown/any first and then to SVGElement doesn't seem like a good DX. I understand that people might deal with SVG less often than with HTML but there should be a clear way of working with SVGs too. Not everyone might figure out how to "properly" cast this as it's not intuitive.
It also seems that there is no good list of "expectations" about the DOM types. A lot of this is gray area and the APIs don't provide full type safety. It would be great if things like this would be documented somewhere.
Happy to have a FAQ of some sort, maybe this could be the first one?
@orta where such a FAQ should live in? this repo? main TS docs?
In here I think, TypeScript's FAQ is already very very long