Skip to content

Local type aliases #3001

@jiripudil

Description

@jiripudil

Feature request

The recent addition of type aliases in configuration file led me to a thought: sometimes I have complex types such as callables or array shapes that are repeated in a single file, and since they are internal to the file, I don't feel comfortable exposing them in a global phpstan.neon.

I'd like to be able to declare something like this at the top of the file:

/**
 * @phpstan-type MyEventListener callable(very, complicated, callable, signature): void
 */

and then just reference MyEventListener in docblocks in the same file.

I believe Psalm supports this to some extent via @psalm-type Alias=type, although it is apparently not documented.

"I may want to implement this" and in fact already have a working prototype of class-scoped aliases, i.e. you can specify a type alias in a class's docblock and use such alias within the class members docblocks. (This seemed to be the easiest direction to take and is imo a good first iteration.)

Before I polish and push the code, I'd like to get some feedback about the idea in general, firstly: is this something you'd want in PHPStan at all?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions