Skip to content

Commit 9eff61f

Browse files
committed
Added generic typing to flatMap method.
1 parent c2798fd commit 9eff61f

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

src/Illuminate/Collections/Enumerable.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,11 @@ public function mapWithKeys(callable $callback);
680680
/**
681681
* Map a collection and flatten the result by a single level.
682682
*
683-
* @param callable(TValue, TKey): mixed $callback
684-
* @return static<int, mixed>
683+
* @template TFlatMapKey of array-key
684+
* @template TFlatMapValue
685+
*
686+
* @param callable(TValue, TKey): (\Illuminate\Support\Collection<TFlatMapKey, TFlatMapValue>|array<TFlatMapKey, TFlatMapValue>) $callback
687+
* @return static<TFlatMapKey, TFlatMapValue>
685688
*/
686689
public function flatMap(callable $callback);
687690

src/Illuminate/Collections/Traits/EnumeratesValues.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,11 @@ public function mapToGroups(callable $callback)
384384
/**
385385
* Map a collection and flatten the result by a single level.
386386
*
387-
* @param callable(TValue, TKey): mixed $callback
388-
* @return static<int, mixed>
387+
* @template TFlatMapKey of array-key
388+
* @template TFlatMapValue
389+
*
390+
* @param callable(TValue, TKey): (\Illuminate\Support\Collection<TFlatMapKey, TFlatMapValue>|array<TFlatMapKey, TFlatMapValue>) $callback
391+
* @return static<TFlatMapKey, TFlatMapValue>
389392
*/
390393
public function flatMap(callable $callback)
391394
{

types/Support/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,12 @@ function ($collection, $count) {
584584
return ['string' => 1];
585585
}));
586586

587-
assertType('Illuminate\Support\Collection<int, mixed>', $collection::make(['string'])
587+
assertType('Illuminate\Support\Collection<int, string>', $collection::make(['string'])
588588
->flatMap(function ($string, $int) {
589589
assertType('string', $string);
590590
assertType('int', $int);
591591

592-
return 1;
592+
return [0 => 'string'];
593593
}));
594594

595595
assertType('Illuminate\Support\Collection<int, User>', $collection->mapInto(User::class));

types/Support/LazyCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,12 @@
480480
return ['string' => 1];
481481
}));
482482

483-
assertType('Illuminate\Support\LazyCollection<int, mixed>', $collection::make(['string'])
483+
assertType('Illuminate\Support\LazyCollection<int, string>', $collection::make(['string'])
484484
->flatMap(function ($string, $int) {
485485
assertType('string', $string);
486486
assertType('int', $int);
487487

488-
return 1;
488+
return [0 => 'string'];
489489
}));
490490

491491
assertType('Illuminate\Support\LazyCollection<int, User>', $collection->mapInto(User::class));

0 commit comments

Comments
 (0)