Uh oh!
There was an error while loading. Please reload this page.
Replaces several DOM methods with weaker typings and closes microsoft/TypeScript#4689 - #885
Conversation
…#4689 The following changes have been made: * All occurences of `getElementById` takes an optional type parameter for manual typing. * All occurences of `getElementsByClassName` takes an optional type parameter for manual typing. * `parentElement` now types to `Element` (See microsoft#4689)
Holger Jeromin (HolgerJeromin)
commented
Jul 23, 2020
This will break many code parts. |
I was thinking about this, but the spec states IMO, if we continue to let wrong types live in this language, the future will be bleak as new interface may be impossible to implement. Considering |
Orta Therox (orta)
commented
Sep 10, 2020
Yeah, I agree with Holger Jeromin (@HolgerJeromin) - I think the move to generics is a good call for usability outside of the common HTML case, but I don't think it should switch to I'll write a longer post in the original TS issue but if this switches to |
Orta Therox (orta)
commented
Sep 10, 2020
Orta Therox (@orta) Sorry for not getting back to you after a while. I've made the changes you proposed. Your arguments are reasonable, particularly because of the possibility of a 'strict-type' module if ever necessary. However, I did not change the |
Holger Jeromin (HolgerJeromin)
commented
Oct 18, 2020
Perhaps the parent case can be more complex handled: forreignObjectHTMLElement parent is svgSvgElement. SvgSvgElement can have svgSvgElement or HTMLElement as parent. Or do i miss something? |
Randolf J. (jrandolf-old)
commented
Oct 18, 2020
Sounds reasonable! I'll make these changes. |
So the changes made so far:
|
| Node getRootNode(optional GetRootNodeOptions options = {}); | ||
| readonly attribute Node? parentNode; | ||
| readonly attribute Element? parentElement; | ||
| readonly attribute HTMLElement? parentElement; |
There was a problem hiding this comment.
Is this a change from upstream?
There was a problem hiding this comment.
Thanks for catching this! Happened during a RegExp replace operation..
Holger Jeromin (HolgerJeromin)
commented
Nov 12, 2020
Can you add similar typings to |
Randolf J. (jrandolf-old)
commented
Nov 12, 2020
Scope creep. There is already another discussion for that since the new template string types will change the playing field. |
Uh oh!
There was an error while loading. Please reload this page.
Orta Therox (orta)
commented
Dec 12, 2020
Thanks! |
Orta Therox (orta)
commented
Jan 6, 2021
#970 reverts this PR - so that we can release 4.2 without this. The revert isn't permanent, but it is too breaking to DefinitelyTyped and so it's likely to be very breaking to the rest of the TS/JS ecosystem and Anders argued that this technique is probably not what we want either way microsoft/TypeScript#42067 (comment) It's going to need another look (and maybe we need to figure out a way to be able to determine breakability better inside PRs in this repo, because it takes a few steps to find out right now). |
Reverts #885 - dom query changes
Felix Becker (felixfbecker)
commented
Jun 21, 2021
It is very weird to me that the type parameter would default to I really like that the TypeScript DOM types are a trustworthy reference for how the types in the DOM actually are, often helping uncover and teaching cases that someone may not even know about (and much easier to read and more discoverable than the DOM spec). I think it would be a shame if TypeScript types moved away from modeling the correct types towards only modeling the majority-of-cases types. It is actually very easy to accidentally write code like e.g. document.getElementById(location.hash.slice(1))?.focus()trusting TypeScript that it would give a type error if this was not correct and forgetting that a user-provided ID could very well match an SVG element, which would not have a I understand the challenges with backwards compatibility, but as a user I'd rather update code to add casts to fix type errors. It wouldn't be the first type error in a dom.d.ts upgrade for more correct types 🙂 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The following changes have been made:
getElementByIdtake an optional type parameter for manual typing.getElementsByClassNametake an optional type parameter for manual typing.parentElementnow types toElement(See Node.parentElement should be Element, not HTMLElement TypeScript#4689)