Skip to content

Commit 328473d

Browse files
committed
Improve types for Collection::whereInstanceOf method
1 parent 6f743e2 commit 328473d

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/Illuminate/Collections/Enumerable.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,9 @@ public function whereNotInStrict($key, $values);
460460
/**
461461
* Filter the items, removing any items that don't match the given type(s).
462462
*
463-
* @param class-string|array<array-key, class-string> $type
464-
* @return static
463+
* @template TWhereInstanceOf
464+
* @param class-string<TWhereInstanceOf>|array<array-key, class-string<TWhereInstanceOf>> $type
465+
* @return static<TKey, TWhereInstanceOf>
465466
*/
466467
public function whereInstanceOf($type);
467468

src/Illuminate/Collections/Traits/EnumeratesValues.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,9 @@ public function whereNotInStrict($key, $values)
679679
/**
680680
* Filter the items, removing any items that don't match the given type(s).
681681
*
682-
* @param class-string|array<array-key, class-string> $type
683-
* @return static
682+
* @template TWhereInstanceOf
683+
* @param class-string<TWhereInstanceOf>|array<array-key, class-string<TWhereInstanceOf>> $type
684+
* @return static<TKey, TWhereInstanceOf>
684685
*/
685686
public function whereInstanceOf($type)
686687
{

types/Support/Collection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,11 @@ function ($collection, $count) {
463463
assertType("Illuminate\Support\Collection<int, array{string: int}>", $collection::make([['string' => 2]])
464464
->whereNotInStrict('string', [2]));
465465

466-
assertType('Illuminate\Support\Collection<int, int|User>', $collection::make([new User, 1])
466+
assertType('Illuminate\Support\Collection<int, User>', $collection::make([new User, 1])
467467
->whereInstanceOf(User::class));
468468

469-
assertType('Illuminate\Support\Collection<int, int|User>', $collection::make([new User, 1])
470-
->whereInstanceOf([User::class, User::class]));
469+
assertType('Illuminate\Support\Collection<int, Exception|User>', $collection::make([new User, 1])
470+
->whereInstanceOf([User::class, Exception::class]));
471471

472472
assertType('User|null', $collection->first());
473473
assertType('User|null', $collection->first(function ($user) {

types/Support/LazyCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,10 @@
359359
assertType("Illuminate\Support\LazyCollection<int, array{string: int}>", $collection::make([['string' => 2]])
360360
->whereNotInStrict('string', [2]));
361361

362-
assertType('Illuminate\Support\LazyCollection<int, int|User>', $collection::make([new User, 1])
362+
assertType('Illuminate\Support\LazyCollection<int, User>', $collection::make([new User, 1])
363363
->whereInstanceOf(User::class));
364364

365-
assertType('Illuminate\Support\LazyCollection<int, int|User>', $collection::make([new User, 1])
365+
assertType('Illuminate\Support\LazyCollection<int, User>', $collection::make([new User, 1])
366366
->whereInstanceOf([User::class, User::class]));
367367

368368
assertType('User|null', $collection->first());

0 commit comments

Comments
 (0)