Skip to content

Generic local type aliases #6099

@MidnightDesign

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

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