Skip to content

Commit a46aafa

Browse files
authored
Improves Collection::mapInto types (#40374)
1 parent 7854c34 commit a46aafa

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/Illuminate/Collections/Enumerable.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,10 @@ public function flatMap(callable $callback);
659659
/**
660660
* Map the values into a new class.
661661
*
662-
* @param class-string $class
663-
* @return static<TKey, mixed>
662+
* @template TMapIntoValue
663+
*
664+
* @param class-string<TMapIntoValue> $class
665+
* @return static<TKey, TMapIntoValue>
664666
*/
665667
public function mapInto($class);
666668

src/Illuminate/Collections/Traits/EnumeratesValues.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,10 @@ public function flatMap(callable $callback)
378378
/**
379379
* Map the values into a new class.
380380
*
381-
* @param class-string $class
382-
* @return static<TKey, mixed>
381+
* @template TMapIntoValue
382+
*
383+
* @param class-string<TMapIntoValue> $class
384+
* @return static<TKey, TMapIntoValue>
383385
*/
384386
public function mapInto($class)
385387
{

types/Support/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@
476476
return 1;
477477
}));
478478

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

481481
assertType('Illuminate\Support\Collection<int, int>', $collection->make([1])->merge([2]));
482482
assertType('Illuminate\Support\Collection<int, string>', $collection->make(['string'])->merge(['string']));

types/Support/LazyCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@
476476
return 1;
477477
}));
478478

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

481481
assertType('Illuminate\Support\LazyCollection<int, int>', $collection->make([1])->merge([2]));
482482
assertType('Illuminate\Support\LazyCollection<int, string>', $collection->make(['string'])->merge(['string']));

0 commit comments

Comments
 (0)