Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.x] Types: Collection chunk without preserving keys #54924

Open
wants to merge 3 commits into
base: 12.x
Choose a base branch
from

Conversation

liamduckett
Copy link
Contributor

Hey, realised #54916 needs some slight type tweaks - added type tests accordingly.

I understand it to still adhere to the Enumerable interface, as static<int, static<int, TValue>> is a subtype of static<int, static> (which is implicitly static<int, static<TKey, TValue>>) as TKey is covariant.

@liamduckett liamduckett changed the title Fix/collection chunk dont preserve keys [12.x] Types: Collection chunk without preserving keys Mar 6, 2025
@@ -1442,7 +1442,7 @@ public function firstOrFail($key = null, $operator = null, $value = null)
*
* @param int $size
* @param bool $preserveKeys
* @return static<int, static>
* @return ($preserveKeys is true ? static<int, static> : static<int, static<int, TValue>>)
Copy link
Member

Choose a reason for hiding this comment

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

Is this syntax supported by both psalm and phpstan?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, yeah:

  1. Psalm
  2. PHPStan

It's not new to the framework either:

* @return ($condition is true ? never : ($condition is non-empty-mixed ? never : TValue))

@taylorotwell
Copy link
Member

@liamduckett does this work with VS Code?

@liamduckett
Copy link
Contributor Author

liamduckett commented Mar 6, 2025

@taylorotwell it does for me - I do have the PHP Intelephense extension though?

Edit: sorry forgot to attach screenshots...

laravel_pr_54924_chunk_preserve_keys
laravel_pr_54924_chunk_dont_preserve_keys

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