Dom
Dom copied to clipboard
Docblock types to show all possibilites
Currently, the returned type of a function like cloneNode() or querySelector is hard-coded to Node and Element respectfully, but there may be any child type returned in reality.
This means that $document->querySelector("a")->href = "/test"; shows up as an error during static analysis, because an Element doesn't have a href property, whereas the actual type returned does (HTMLAnchorElement).
The developer must type-hint the object returned by the DOM API, so it would be better for IDEs and static analysis if the available methods/properties were shown, rather than showing an error for all objects.
This solution won't work. If static analysis is complaining that there isn't a href attribute, it will still complain that there might not be a href attribute. Without being specific, you'll always get the complaint.
I'm going to leave this open until certain common functions are type hinted to return Element rather than Node (because even though that's off-spec, it's definitely what will be returned), as Node is really the limiting factor here.