Repository navigation
Replies: 1 comment
|
Psalm does not currently have parameterized type aliases of the form
/** @psalm-type PhoneType = array{phone: string} */while For this particular shape, the reusable generic boundary therefore needs to be a templated declaration rather than an alias. For example, if the wrapper is part of an API: /**
* @template T
*/
final class Wrapper
{
/** @var list<list<T>> */
public array $value;
/** @param list<list<T>> $value */
public function __construct(array $value)
{
$this->value = $value;
}
}
/** @var Wrapper<string> */
$s = new Wrapper([['a']]);
/** @var Wrapper<int> */
$i = new Wrapper([[1]]);If you only need aliases and not a wrapper object, the practical alternative is separate concrete aliases ( So the proposed |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Say, I have the following variables:
Is there a support of templating for a type? What I want would be something similar to:
All reactions