Skip to content

Conversation

@jnoordsij
Copy link
Contributor

This PR is a follow-up to:

  1. [12.x] Fixup Eloquent Collection (param) docblocks #58170 as although this fixes inheritance, it also 'exposed' an incorrect typing on the countBy method added in [12.x] Improve countBy docblock in Collection to allow for enum callback #56856 lacking a set of parentheses
  2. [12.x] Improve countBy docblock in Collection to allow for enum callback #56856 in adding a more fine-grained return type for the countBy method, which is subsequently also applied to the groupBy and keyBy methods.

It also adds some tests to the types to illustrate the behavior is currently incorrect and fixed by subsequent commits.

}, preserveKeys: true));

assertType('Illuminate\Support\Collection<(int|string), User>', $collection->keyBy('name'));
assertType('Illuminate\Support\Collection<string, User>', $collection->keyBy(function ($user, $int) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW apparently the type inheritance got 'overspecific' here, actualy inferring the very specific return type 'foo' where it previously didn't. Although this is semantically all correct, I'm not sure why this happens only now and here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant