Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docblock types to show all possibilites #293

Open
g105b opened this issue Oct 4, 2021 · 1 comment
Open

Docblock types to show all possibilites #293

g105b opened this issue Oct 4, 2021 · 1 comment
Labels
enhancement Improvement to existing functionality

Comments

@g105b
Copy link
Member

g105b commented Oct 4, 2021

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.

@g105b g105b added the enhancement Improvement to existing functionality label Oct 4, 2021
@g105b
Copy link
Member Author

g105b commented Oct 13, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement to existing functionality
Projects
None yet
Development

No branches or pull requests

1 participant