-
Notifications
You must be signed in to change notification settings - Fork 360
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
Type Aliases #4562
Comments
TysonAndre
added a commit
to TysonAndre/phan
that referenced
this issue
Oct 2, 2021
… or element comments These aliases will apply to remaining statements in the current **top-level namespace blocks,** similar to use statements, but can also be defined in methods and apply to subsequent methods. This can be of use in avoiding repetition of phpdoc for long type definitions. ```php /** * @type-alias UserData = array{name: string, id: int, createdAt: DateTime} * (applies to this and all subsequent AST nodes in the namespace block) */ class ExampleElementWithPHPDoc { } // Alternate inline string version to work around php-ast limitations '@phan-type UserData = array{name: string, id: int, createdAt: DateTime}'; // The UserData alias is still defined and can be used in other statements namespace XYZ; // The UserData alias is no longer defined in the new namespace block. ``` Closes phan#4562
TysonAndre
added a commit
to TysonAndre/phan
that referenced
this issue
Oct 2, 2021
… or element comments These aliases will apply to remaining statements in the current **top-level namespace blocks,** similar to use statements, but can also be defined in methods and apply to subsequent methods. This can be of use in avoiding repetition of phpdoc for long type definitions. ```php /** * @type-alias UserData = array{name: string, id: int, createdAt: DateTime} * (applies to this and all subsequent AST nodes in the namespace block) */ class ExampleElementWithPHPDoc { } // Alternate inline string version to work around php-ast limitations '@phan-type UserData = array{name: string, id: int, createdAt: DateTime}'; // The UserData alias is still defined and can be used in other statements namespace XYZ; // The UserData alias is no longer defined in the new namespace block. ``` Closes phan#4562
TysonAndre
added a commit
to TysonAndre/phan
that referenced
this issue
Oct 2, 2021
… or element comments These aliases will apply to remaining statements in the current **top-level namespace blocks,** similar to use statements, but can also be defined in methods and apply to subsequent methods. This can be of use in avoiding repetition of phpdoc for long type definitions. ```php /** * @type-alias UserData = array{name: string, id: int, createdAt: DateTime} * (applies to this and all subsequent AST nodes in the namespace block) */ class ExampleElementWithPHPDoc { } // Alternate inline string version to work around php-ast limitations '@phan-type UserData = array{name: string, id: int, createdAt: DateTime}'; // The UserData alias is still defined and can be used in other statements namespace XYZ; // The UserData alias is no longer defined in the new namespace block. ``` Closes phan#4562
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey there, thanks for the great work on Phan.
I was wondering if Phan supported, or plans to support type aliases within it's type system? I've had a look through the docs and issues and cannot find anything relevant to the topic so i thought i'd ask.
For example. phpstan has support for the following:
https://phpstan.org/writing-php-code/phpdoc-types#local-type-aliases
Which makes defining and reusing types simple.
The biggest value is for code bases that are using a lot of shaped arrays. Updating all the locations that shaped array exists can become quite cumbersome, but defining the array shape to Phan empowers it's analysis greatly.
The text was updated successfully, but these errors were encountered: