Skip to content

Commit

Permalink
Merge pull request #40879 from zingimmick/fix-type-definition
Browse files Browse the repository at this point in the history
[9.x] Improves `Support\Collection` each method type definition
  • Loading branch information
nunomaduro authored Feb 9, 2022
2 parents ca33630 + 23a2675 commit dfef6a1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Enumerable.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function duplicatesStrict($callback = null);
/**
* Execute a callback over each item.
*
* @param callable(TValue): mixed $callback
* @param callable(TValue, TKey): mixed $callback
* @return $this
*/
public function each(callable $callback);
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Traits/EnumeratesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function dump()
/**
* Execute a callback over each item.
*
* @param callable(TValue): mixed $callback
* @param callable(TValue, TKey): mixed $callback
* @return $this
*/
public function each(callable $callback)
Expand Down
4 changes: 4 additions & 0 deletions types/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@
assertType('Illuminate\Support\Collection<int, User>', $collection->each(function ($user) {
assertType('User', $user);
}));
assertType('Illuminate\Support\Collection<int, User>', $collection->each(function ($user, $int) {
assertType('int', $int);
assertType('User', $user);
}));

assertType('Illuminate\Support\Collection<int, array{string}>', $collection::make([['string']])
->eachSpread(function ($int, $string) {
Expand Down

0 comments on commit dfef6a1

Please sign in to comment.