Skip to content

Generic local type aliases #6099

Description

@MidnightDesign

Feature request

Local type aliases (@phpstan-type Foo 'a'|'b') should be allowed to be generic:

/**
 * @phpstan-type MyType<T> array{create: callable(): T, test: callable(T): void}
 */
class HelloWorld
{
    /**
     * @template U
     * @param MyType<U> $case
     * @return U
     */
    public static function takesMyType(array $case): mixed
    {
        $theThing = $case['create']();

        $case['test']($theThing);
		
        return $theThing;
    }
}

https://phpstan.org/r/9dd37e37-8838-4b9d-ac79-45ed361cbf55

The equivalent TypeScript code with usage examples

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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