Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:7.3frommtarld:feat/type-aliases
Feb 19, 2025

Conversation

mtarld
Copy link
Contributor

@mtarldmtarld commentedFeb 18, 2025
edited
Loading

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
Issues
LicenseMIT

Add type aliasing support inTypeContext andStringTypeResolver, which enables the read of@phpstan-type and@phpstan-import-type.

With this PR, the following code will be properly understood by TypeInfo (before, it used to throw anUnhandledException):

/** * @phpstan-type TypeAlias = array<string, list<bool>> */finalclass Dummy{/**     * @var TypeAlias     */publicmixed$aliasedType;}

darthf1, Neirda24, and zmitic reacted with heart emojialexandre-daubois reacted with rocket emoji
@carsonbotcarsonbot added this to the7.3 milestoneFeb 18, 2025
@mtarldmtarldforce-pushed thefeat/type-aliases branch 2 times, most recently from34dbc2f to14c1e1eCompareFebruary 18, 2025 16:01
@nicolas-grekas
Copy link
Member

Note that the portable syntax (= understood by phpstan & psalm & phpstorm) is this one:
@phpstan-type TypeAlias = array<string, list<bool>>

@Neirda24
Copy link
Contributor

Note that the portable syntax (= understood by phpstan & psalm & phpstorm) is this one:@phpstan-type TypeAlias = array<string, list<bool>>

But it is not how people usually write it I think. is it ?

@nicolas-grekas
Copy link
Member

They have to if they want support from their tools...

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment
edited
Loading

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?

@Neirda24
Copy link
Contributor

They have to if they want support from their tools...

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=. Current projects / libraries that uses these kind of features don't always use the=. Requiring it would restrict people from using the TypeInfo on tools that did not follow the symfony requirements.

@Neirda24
Copy link
Contributor

They have to if they want support from their tools...

More on this. The documentationhttps://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.

@mtarld
Copy link
ContributorAuthor

@Neirda24,@nicolas-grekas, I updated the code/tests to make it work for@psalm-*,@phpstan-*, with and without the= so that it matches most of the use cases.

Neirda24, smnandre, and zmitic reacted with heart emoji

@nicolas-grekas
Copy link
Member

Thank you@mtarld.

@nicolas-grekasnicolas-grekas merged commit77b8358 intosymfony:7.3Feb 19, 2025
9 of 11 checks passed
@mtarldmtarld deleted the feat/type-aliases branchFebruary 19, 2025 16:27
@Neirda24
Copy link
Contributor

So fast ! Thank you@mtarld !

mtarld reacted with laugh emoji

@fabpotfabpot mentioned this pull requestMay 2, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@Neirda24Neirda24Neirda24 left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
7.3
Development

Successfully merging this pull request may close these issues.

4 participants
@mtarld@nicolas-grekas@Neirda24@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp