diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index 0b82fe76939d..ee017e28a7fe 100755 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -368,9 +368,11 @@ function windows_os() /** * Return the given value, optionally passed through the given callback. * - * @param mixed $value - * @param callable|null $callback - * @return mixed + * @template TValue + * + * @param TValue $value + * @param (callable(TValue): TValue)|null $callback + * @return TValue */ function with($value, callable $callback = null) { diff --git a/types/Support/Helpers.php b/types/Support/Helpers.php new file mode 100644 index 000000000000..08a8bb26f374 --- /dev/null +++ b/types/Support/Helpers.php @@ -0,0 +1,15 @@ +save()); +assertType('User', with(new User(), function (User $user) { + return $user; +})); + +assertType('int|User', with(new User(), function ($user) { + assertType('int|User', $user); + + return 10; +}));