es-toolkit 1.16.0-dev.480 → 1.16.0-dev.482

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,18 +3,18 @@
3
3
  * based on a transformation function.
4
4
  *
5
5
  * This function takes an array and a transformation function
6
- * that converts each item in the array to a string. It then
6
+ * that converts each item in the array to a key. It then
7
7
  * counts the occurrences of each transformed item and returns
8
8
  * an object with the transformed items as keys and the counts
9
9
  * as values.
10
10
  *
11
11
  * @template T - The type of the items in the input array.
12
- *
12
+ * @template K - The type of keys.
13
13
  * @param {T[]} arr - The input array to count occurrences.
14
- * @param {(item: T) => string} mapper - The transformation function that maps each item to a string key.
15
- * @returns {Record<string, number>} An object containing the transformed items as keys and the
14
+ * @param {(item: T) => K} mapper - The transformation function that maps each item to a key.
15
+ * @returns {Record<K, number>} An object containing the transformed items as keys and the
16
16
  * counts as values.
17
17
  */
18
- declare function countBy<T>(arr: T[], mapper: (item: T) => string): Record<string, number>;
18
+ declare function countBy<T, K extends PropertyKey>(arr: readonly T[], mapper: (item: T) => K): Record<K, number>;
19
19
 
20
20
  export { countBy };
@@ -3,18 +3,18 @@
3
3
  * based on a transformation function.
4
4
  *
5
5
  * This function takes an array and a transformation function
6
- * that converts each item in the array to a string. It then
6
+ * that converts each item in the array to a key. It then
7
7
  * counts the occurrences of each transformed item and returns
8
8
  * an object with the transformed items as keys and the counts
9
9
  * as values.
10
10
  *
11
11
  * @template T - The type of the items in the input array.
12
- *
12
+ * @template K - The type of keys.
13
13
  * @param {T[]} arr - The input array to count occurrences.
14
- * @param {(item: T) => string} mapper - The transformation function that maps each item to a string key.
15
- * @returns {Record<string, number>} An object containing the transformed items as keys and the
14
+ * @param {(item: T) => K} mapper - The transformation function that maps each item to a key.
15
+ * @returns {Record<K, number>} An object containing the transformed items as keys and the
16
16
  * counts as values.
17
17
  */
18
- declare function countBy<T>(arr: T[], mapper: (item: T) => string): Record<string, number>;
18
+ declare function countBy<T, K extends PropertyKey>(arr: readonly T[], mapper: (item: T) => K): Record<K, number>;
19
19
 
20
20
  export { countBy };