Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

kayw-geek
Copy link
Contributor

Description

Improves static analysis type inference for Collection keys() and all() methods.

Changes:

  • keys(): Return type from Collection<int, TKey> to Collection<never, TKey>
  • all(): Return type to list<TValue> when TKey is never

Before:

/** @var list<int> $list */ // Manual annotation required
$list = $collection->keys()->all();
array_is_list($list);

After:

$list = $collection->keys()->all(); // Automatically inferred as list<int>
array_is_list($list);

@kayw-geek kayw-geek changed the title Improve Collection type inference for keys() and all() methods [12.x] Improve Collection type inference for keys() and all() methods Aug 5, 2025
@kayw-geek kayw-geek force-pushed the feature/improve-generic-for-collection branch 2 times, most recently from db19139 to 29849e5 Compare August 5, 2025 08:39
@kayw-geek kayw-geek force-pushed the feature/improve-generic-for-collection branch from 29849e5 to ec97170 Compare August 5, 2025 08:42
@shaedrich
Copy link
Contributor

Does never make sense here? Isn't TKey always array-key which can be narrowed down to either string or int if possible by the underlying data? 🤨

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