Skip to content

"Array shapes" with extra and optional keys problem #3172

@vhenzl

Description

@vhenzl

This works as expected: https://phpstan.org/r/c11d6f2d-ce6b-4338-a7fc-6bd6695c25cd
The abc() accepts a shape with extra keys.

However, if I update parameter type of abc() to make some of its keys optional, PHPStan complains: https://phpstan.org/r/82e97898-71bf-496b-abe9-0d79f7caf757

And it complains even if the given key is optional in both parameter and argument types: https://phpstan.org/r/7ac7677c-c1f9-4393-bd44-e70ef3d5935e

Expected behaviour

An array shape can accept another array shape with extra keys and the accepting type can have its keys optional regardless of their optionality in the assigned type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions