forked from larastan/larastan
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
bugSomething isn't workingSomething isn't working
Description
To get pivots working with custom collections it seems I have to permit that the custom collections can be extended. To avoid having to specify it's type everywhere we use it I do the following to also set it's default type:
/**
* @template T of Product = Product
* @extends Collection<int, T>
*/
class ProductCollection extends Collection {}But now I have several errors elsewhere in the application where the return type appears as:
Dumped type: Luxplus\Core\Database\Model\Products\ProductCollection<int>
Which then results in the following false positives:
212 Parameter #1 $callback of method Illuminate\Support\Collection<int,int>::sortBy() expects array<array{string, string}|(callable(int, int):
mixed)|string>|(callable(int, int): mixed)|string, Closure(Model\Products\Product): int<0, max> given.
For this code:
$products = Product::all();
\PHPStan\dumpType($products);
$products->sortBy(fn(Product $product) => $sortMap[$product->id]);Could you help clarify if I'm doing something wrong or is this an actual bug?
Without the default i get expectedly get a lot of Method ProductCollection::getProducts() return type with generic class ProductCollection does not specify its types: TModel
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working