DataCollection access with correct type without phpdocs #90
-
I'm using phpstan, so I have to use the following phpdoc when I use a DataCollection class Test extends Data
{
public function __construct(
/** @var DataCollection<TestChild> */
public DataCollection $children,
) {
}
} However, the ArrayAccess offsetGet function always returns a Data object. So the following: /** @var Test $test */
$child = $test->children[0]; will result in the $child being type Data instead of TestChild, as the offsetGet always returns Data: public function offsetGet($offset): Data
{
return $this->items->offsetGet($offset);
} Is there any way this can be automatically resolved to the correct data class? Right now I have to add a phpdoc to tell my IDE it is not a Data object but a TestChild object in order to get autocomplete: /** @var TestChild $child */
$child = $test->children[0]; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @iamrgroot, this actually requires generics within DataCollection, something we're working on for the v2 release! |
Beta Was this translation helpful? Give feedback.
Hi @iamrgroot, this actually requires generics within DataCollection, something we're working on for the v2 release!