Skip to content

Conversation

@sebdesign
Copy link
Contributor

Similarly to #38538, this PR makes the LazyCollection generic.

I haven't tested this with PHPStorm or Psalm, but in VSCode + PHPStan extension it works great.

Also:

  • Fixed some minor issues with the Support\Collection types
  • Added missing tests for some methods

There are still a few issues with the constructors and the make() method of the collections:

  • The Support\LazyCollection needs to widen the type of items it accepts, because it accepts callables that return Generators, but the Support\Collection does not accept that. I have extended the make method and it works as expected.

  • For some reason new Eloquent\Collection([new User()]) returns Eloquent\Collection<(int|string), Eloquent\Model> instead of Eloquent\Collection<int, User>. If I extend the constructor it works (but I haven't included this).

@sebdesign sebdesign changed the title Improve Support\LazyCollection type definitions [9.x] Improve Support\LazyCollection type definitions Nov 6, 2021
@driesvints
Copy link
Member

Seems like tests are failing here. Feel free to markt his as ready when tests are passing.

@driesvints driesvints marked this pull request as draft November 6, 2021 14:27
@sebdesign
Copy link
Contributor Author

All good now! Maybe @nunomaduro would like to review this?

@driesvints driesvints marked this pull request as ready for review November 6, 2021 14:35
@driesvints
Copy link
Member

Ping @JosephSilber

@driesvints driesvints requested a review from nunomaduro November 6, 2021 14:36
@sebdesign
Copy link
Contributor Author

Also, @JosephSilber I think there is an issue with the internal types the LazyCollection: The makeIterator returns a Traversable but it is used as if it's an Iterator.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants