Skip to content

Generics for key K of a generic array T #7094

@Seldaek

Description

@Seldaek

Feature request

I am trying to define generic types for a set of array-wrapping methods, which allow reading/writing a key. Something not so uncommon (think Symfony's ParameterBag and similar).

I tried setting it up like this which works partially (for keys) but the values are completely untyped:

https://phpstan.org/r/85335c46-5a90-4dca-838a-1d033780e443

A suggested solution would be to add a second param to value-of<> to allow retrieving the type of a specific key like value-of<T, K>, which you can see illustrated here although this fails to parse:

https://phpstan.org/r/4afa4369-83d9-47b3-b82f-22cf3ad7f753

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions