Replace \Closure(...) with \Closure(mixed...)
See https://github.com/phpstan/phpstan/issues/12954
The \Closure(...) is not documented, by the way. This page only says that a type can be suffixed with ....
I originally removed this syntax to support PHPStan: https://github.com/amphp/amp/commit/138801fb68cfc9c329da8a7b39d01ce7291ee4b0
So this has now changed?
🤦🤦🤦
Well, the only thing I can tell is that with mixed... it now works in both analyzers:
https://phpstan.org/r/681abd9e-ec0f-4edb-ab82-134e3be7088e
https://psalm.dev/r/2dd7ca2ae0
In fact my solution is wrong: https://phpstan.org/r/9c17bb5f-4087-4201-b684-72a28b0e069c .
PHPStan is correct: you cannot pass a Closure with narrower parameters to a Closure with
wider parameters, since parameters are contravariant.
This is how async function would look like in TypeScript (thanks to @klimick for helping with the snippet). @ondrejmirtes is already discussing smth similar: https://github.com/phpstan/phpstan/issues/8214.
Here's the possible solution:
- for PHPStan use a
Closurewith a bunch ofneverparameters for to indicate thatClosuremight have parameters with any wider types and suppress the place where it is invoked, - for Psalm keep the current
Closure(...)syntax, because Psalm does not allow to haveneverparameters.
https://phpstan.org/r/4e98ea03-a863-4b39-8fcf-07cfdc2e8ea4 https://psalm.dev/r/cda9b2565b