Skip to content

Commit 8d61a26

Browse files
authored
Chore: Add types to iterable_to_array() (#27)
1 parent 3a125c1 commit 8d61a26

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/iterable-functions.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ function iterable_map(iterable $iterable, callable $map): iterable
2727
}
2828

2929
/**
30-
* Copy the iterable into an array. If the iterable is already an array, return it.
30+
* Copy the iterable into an array.
3131
*
32-
* @param iterable<mixed> $iterable
32+
* @param iterable<array-key, TValue> $iterable
3333
* @param bool $preserveKeys [optional] Whether to use the iterator element keys as index.
3434
*
35-
* @return array<mixed>
35+
* @return array<array-key, TValue>
36+
*
37+
* @psalm-return ($preserveKeys is true ? array<TKey, TValue> : array<int, TValue>)
38+
* @psalm-template TKey as array-key
39+
* @phpstan-template TKey
40+
* @template TValue
3641
*/
3742
function iterable_to_array(iterable $iterable, bool $preserveKeys = true): array
3843
{

0 commit comments

Comments
 (0)