phptools-docs
phptools-docs copied to clipboard
generic issue
<?php
/**
* @template Tkey
* @template TValue
*/
class Collection
{
/**
* @template TMap
* @param callable(TValue, Tkey): TMap $callable
* @return static<TKey, TMap>
*/
public function map($callable)
{
}
}
/**
* @template TKey
* @template TValue
*
* @param iterable<TKey, TValue>|array<TValue> $iter
* @return Collection<TKey, TValue>
*/
function collection($iter)
{
}
$c = collection([1, 2, 3]);
$c1 = $c->map(function ($value, $key): string {
// $value should be int
return 'string';
}); // $c1 should be Collection<TKey, string> instead Collection<TKey, int>
Thank you!
We have ignored the generic arguments for static in this case. The $value type may be a bit more difficult, working on it.
- [x] bind TMap in
static<TKey, TMap> - [x] resolve lambda's parameter
$valuefrom the calling method generic parameter description
A small bug related to hover differences in vendor:
Implemented inferring for lambda parameters + inlay type hint:
$c->map(function (/*int*/ $value, $key): string {
// $value is int
});
It will be in the next update.
Closing the issue.
The incorrect (double) hover will be fixed separately.