You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When wrapping callable, we might want to describe that the callable we return will take the same arguments that the one we got as an argument. (see phpstan/phpstan#6813 for a short discussion on the subject)
Here is an exemple of what the syntax could look like:
I like that it feels right to "expand" the array of types with callable(...A), but I know it might be confusing given callable(A...) as a different meaning
some other use cases for this feature:
/** * @template A1 * @template Arest of array<mixed> * @template R * @param callable(A1, ...Arest): R * @return callable(...Arest): R */functioncurry(callable$f, mixed$arg1): callable {
returnstatic fn (...$args) => $f($arg1, ...$args);
}
/**
* @template A of array<mixed>
* @template Rf
* @template Rg
* @param callable(...A): Rf$f
* @param callable(Rf): Rg$g
* @return callable(...A): Rg
function combine(callable $f, callable $g): callable {
return static fn (...$args) => $g($f(...$args));
}
Psalm output (using commit 16b24bd):
ERROR: InvalidArgument - 12:42 - Argument 1 of castToStringWrapper expects Closure(array<array-key, mixed>...):int, but pure-Closure(int, int):int provided
INFO: UnusedVariable - 12:1 - $myRandomStringInt is never referenced or the value is not used
Feature request
When wrapping callable, we might want to describe that the callable we return will take the same arguments that the one we got as an argument. (see phpstan/phpstan#6813 for a short discussion on the subject)
Here is an exemple of what the syntax could look like:
https://psalm.dev/r/4e9c0e1d18
I like that it feels right to "expand" the array of types with callable(...A), but I know it might be confusing given callable(A...) as a different meaning
some other use cases for this feature:
copied from phpstan/phpstan#6873
The text was updated successfully, but these errors were encountered: