From 1abcca2b8af742bcbffcf54a70c455a99f787061 Mon Sep 17 00:00:00 2001 From: Felipe Dalcin Date: Mon, 28 Feb 2022 09:33:28 -0300 Subject: [PATCH] Add generics type definition --- src/Illuminate/Collections/Enumerable.php | 2 +- src/Illuminate/Collections/Traits/EnumeratesValues.php | 2 +- types/Support/Collection.php | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Collections/Enumerable.php b/src/Illuminate/Collections/Enumerable.php index b9979464cd9d..9546d4e52f48 100644 --- a/src/Illuminate/Collections/Enumerable.php +++ b/src/Illuminate/Collections/Enumerable.php @@ -805,7 +805,7 @@ public function random($number = null); * @template TReduceInitial * @template TReduceReturnType * - * @param callable(TReduceInitial|TReduceReturnType, TValue): TReduceReturnType $callback + * @param callable(TReduceInitial|TReduceReturnType, TValue, TKey): TReduceReturnType $callback * @param TReduceInitial $initial * @return TReduceReturnType */ diff --git a/src/Illuminate/Collections/Traits/EnumeratesValues.php b/src/Illuminate/Collections/Traits/EnumeratesValues.php index 6b20843e3913..fec550211710 100644 --- a/src/Illuminate/Collections/Traits/EnumeratesValues.php +++ b/src/Illuminate/Collections/Traits/EnumeratesValues.php @@ -745,7 +745,7 @@ function ($carry, $callback) { * @template TReduceInitial * @template TReduceReturnType * - * @param callable(TReduceInitial|TReduceReturnType, TValue): TReduceReturnType $callback + * @param callable(TReduceInitial|TReduceReturnType, TValue, TKey): TReduceReturnType $callback * @param TReduceInitial $initial * @return TReduceReturnType */ diff --git a/types/Support/Collection.php b/types/Support/Collection.php index a2eaead80465..e3f3e48103d5 100644 --- a/types/Support/Collection.php +++ b/types/Support/Collection.php @@ -634,6 +634,14 @@ function ($collection, $count) { assertType('User', $user); assertType('int', $int); + return 1; + }, 0)); +assertType('int', $collection + ->reduce(function ($int, $user, $key) { + assertType('User', $user); + assertType('int', $int); + assertType('int', $key); + return 1; }, 0));