-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[TypeInfo] Add type alias support #59804
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
Conversation
34dbc2f to
14c1e1e
Compare
|
Note that the portable syntax (= understood by phpstan & psalm & phpstorm) is this one: |
src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithPhpDoc.php
Outdated
Show resolved
Hide resolved
But it is not how people usually write it I think. is it ? |
|
They have to if they want support from their tools... |
14c1e1e to
cd159cf
Compare
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.
Can you add a test case using psalm-type just to confirm phpstan's parser handles both?
hmmm IMO when this PR is merged it must not enforce one specific way of writing things with these tools. It should support both with and without |
cd159cf to
dcceca6
Compare
More on this. The documentation https://phpstan.org/writing-php-code/phpdoc-types#local-type-aliases doesn't even mention this. I asked Ondrej a while back on symfony's slack about this but he didn't tought it was worth adding it to documentation. |
|
@Neirda24, @nicolas-grekas, I updated the code/tests to make it work for |
src/Symfony/Component/TypeInfo/TypeContext/TypeContextFactory.php
Outdated
Show resolved
Hide resolved
dcceca6 to
6050915
Compare
src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithPhpDoc.php
Outdated
Show resolved
Hide resolved
6050915 to
0689038
Compare
src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithTypeAliases.php
Outdated
Show resolved
Hide resolved
0689038 to
d0d85af
Compare
|
Thank you @mtarld. |
|
So fast ! Thank you @mtarld ! |
Add type aliasing support in
TypeContextandStringTypeResolver, which enables the read of@phpstan-typeand@phpstan-import-type.With this PR, the following code will be properly understood by TypeInfo (before, it used to throw an
UnhandledException):