-
Notifications
You must be signed in to change notification settings - Fork 430
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
Add support for the key-of<...>
type
#800
Add support for the key-of<...>
type
#800
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When TypeNodeResolver returns ErrorType, it's picked up by existing rules, for example: https://phpstan.org/r/2ae98fc7-9829-42bc-8a25-51e4ef022dad ("contains unresolvable type")
The tests should be done in NodeScopeResolverTest
.
Also please add support for value-of
.
Since it's a separated feature (although it works basically the same), wouldn't be better to implement
I took as reference the |
Since they're closely connected and the implementation is just three lines of code, I want them together.
I don't see this being possible without major refactoring, it certainly shouldn't be a concern for this PR |
Ok, I've added the missing feature
Absolute agree, if that's the case 😃
I've added them, are they enough? I would have expected also some tests to assert that when a wrong value is given an error is thrown, but in this file it looks like all tests just assert the type is the expected one 🤔 |
You can add tests for the rule that you expect to report an error. |
Done. PR is ready for review, let me know if there is something that I still have to do or feel free to make the changes yourself if you want |
Thank you! Feel free to update the docs at https://github.com/phpstan/phpstan/edit/master/website/src/writing-php-code/phpdoc-types.md (https://phpstan.org/writing-php-code/phpdoc-types) |
Fixes phpstan/phpstan#6084. This is my attempt at implementing the
key-of<...>
type borrowed from Psalm. However, I'm not sure where I should place the tests as I see a lot of files, but none that looks the right one. Also, Psalm tells the user precise errors when an invalid value is used as generic argument of thekey-of
type, however theresolveGenericTypeNode()
method cannot return aRuleError
and so I wonder how I could return a custom error message for certain cases. Any advice on these two qustions would be highly appreciated