New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request for enhancement with variadics #664
Comments
I won't do exactly what you asked, but I can have Psalm produce an error message similar to the one it produces here:
/**
* @param callable(DateTime):mixed $c
* @param DateTime[] $arr
* @return mixed[]
*/
function datetimeArrayMapper(callable $c, array $arr) : array {
$new_arr = [];
foreach ($arr as $a) {
$new_arr[] = $c($a);
}
return $new_arr;
}
function foo(DateTime ...$dateTimes) : array {
return datetimeArrayMapper(
function ($dateTime) : string {
return "hello";
},
$dateTimes
);
} |
Actually that's not useful either. |
Related to #204 |
I wasn't aware of the callable(T1):T2 syntax- was that part of your discarded resolution, or is it already in psalm? |
@WDD-Marv It's in dev-master only, there was no release since it was added AFAIK. |
Yup, hopefully a release tonight with that feature. The problem with adding an required param type of |
I would like this feature. https://psalm.dev/r/7790a6ea53 $ints = [1, 2, 3, 4];
$ints2 = array_filter($ints, function ($int) {
return $int->foo();
}); This example emits a few infos but no errors. Most modern languages allow emitting types in closures when it can be inferred (Swift, C#, Rust, etc.). I only really add them because it helps with static analysis and my IDE. Psalm could still error when the type cannot be inferred of course. |
Solved (in a slightly hacky fashion) using the scaffolding I added yesterday to fix #1600 This now typechecks (and Psalm finds bugs in the |
could psalm infer a closure param type if the input to array_map was taken from a typed variadic ? (i.e. to upgrade the error message from "could not infer type")
The text was updated successfully, but these errors were encountered: