-
-
Notifications
You must be signed in to change notification settings - Fork 932
Closed
Description
Bug report
I encountered an oddity while trying to figure out how to work with array shapes vs functions on DTOs using generics. A method that omits the native return type and only uses phpdoc (or specifies mixed) resolves to the type expected, but once a PHP type is also specified it emits a subtype error and no longer resolves to the PHPDoc type.
PHPDoc tag @return with type array{a: string, b: bool, c: int, d: float}[TKey] is not subtype of native type bool|float|int|string.
return.phpDocType
Dumped type: bool|float|int|string
While either of these works as expected:
/**
* @template TKey of key-of<Bob>
* @param TKey $key
* @return Bob[TKey]
*/
public function x(string $key) public function x(string $key): mixedWould mixed actually be the best / correct usage here, or ...?
Code snippet that reproduces the problem
https://phpstan.org/r/65fce4bf-83a1-414e-9189-0418e945b0a4
Expected output
Dumped type: bool
Did PHPStan help you today? Did it make you happy in any way?
No response
Metadata
Metadata
Assignees
Labels
No labels