You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
Currently, the returned type of a function like
cloneNode()
orquerySelector
is hard-coded toNode
andElement
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 anElement
doesn't have ahref
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.
The text was updated successfully, but these errors were encountered: