I don't know why, my vscode only hint while foreach for the array hint
The array typehint defines:
/**
* Basic trustocean products
*
* @return \Illuminate\Database\Eloquent\Collection|\App\Models\Product[]
*/
function basic_trustocean_products() {}
Tests

as the screenshot shows, it works while foreach.
foreach (basic_trustocean_products() as $product) {
$product->name; // here it can hint
}

But does not work while array index.
$products = basic_trustocean_products();
$products[0]->name; // it can't hint
~I can't reproduce with the below snippet. I wonder if there is some other assignment to $products above line 110 that could be causing it to fail?~
Seems it is the collection class that causes problems. Works with just Product[].
<?php
class Collection implements ArrayAccess
{
}
class Product
{
public $name;
}
/** @return Collection|Product[] */
function basic_trustocean_products()
{
return [new Product];
}
$products = basic_trustocean_products();
$products[0]->
Fixed in 1.3. Also, any class that is an instance of ArrayAccess will also be able to be typed as MyClass<TKey, TValue> in 1.3. So in the original example:
/**
* Basic trustocean products
*
* @return \Illuminate\Database\Eloquent\Collection<int, \App\Models\Product>
*/
function basic_trustocean_products() {}
Most helpful comment
Fixed in 1.3. Also, any class that is an instance of
ArrayAccesswill also be able to be typed asMyClass<TKey, TValue>in 1.3. So in the original example: