You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request]: allow type aliases to be imported from non-class files #13315
It, however, does not. Currently, imports can only be done from above a class. This unfortunatly disqualifies the usage of type aliases outside of classes.
I don't have a strong preference on how this should work, as long as it does I'd be happy. Here are some ideas I think could be helpful in general:
// 1️⃣ import from function docs/** * @phpstan-import-type PassThroughArray from View * @param PassThroughArray $data */functionview(array$data): View {}
// 2️⃣ import from under non-class namespace(s)namespaceSomethingOne/** * @phpstan-import-type PassThroughArray from View */// functions herenamespaceSomethingTwo/** * @phpstan-import-typeBlub from View $data */// functions here// 3️⃣ extra: import from docs shorthand/** @param PassThroughArray from View $data */functionview(array$data): View {}
Perhaps, 1️⃣ and 3️⃣ could also be interesting for classes.
Did PHPStan help you today? Did it make you happy in any way?
It always helps! Thanks for your hard work! ❤️
Reacted by Dieter Beck, inilim, Gottem, jiw-mh and John Blackbourn
Also added support for generic aliases (@phpstan-type Foo<T> = array{a: T}) and recursive aliases (@phpstan-type Nested = array<string, string|Nested>) recently.
Activity
ondrejmirtes commentedon Dec 3, 2026
Declaring and importing type aliases is now possible thanks to phpstan/phpstan-src#7295.
Also added support for generic aliases (
@phpstan-type Foo<T> = array{a: T}) and recursive aliases (@phpstan-type Nested = array<string, string|Nested>) recently.NickSdot commentedon Dec 3, 2026
Thanks Ondrej!