20
20
21
21
/// <reference types="@stdlib/types"/>
22
22
23
- import { Collection } from '@stdlib/types/object ' ;
23
+ import { Collection } from '@stdlib/types/array ' ;
24
24
25
25
/**
26
26
* Interface defining function options.
@@ -37,15 +37,15 @@ interface Options {
37
37
*
38
38
* @returns object key
39
39
*/
40
- type Nullary = ( ) => string | symbol ;
40
+ type Nullary = ( ) => string | symbol | number ;
41
41
42
42
/**
43
43
* Specifies which group an element in the input collection belongs to.
44
44
*
45
45
* @param value - collection value
46
46
* @returns object key
47
47
*/
48
- type Unary = ( value : any ) => string | symbol ;
48
+ type Unary < T > = ( value : T ) => string | symbol | number ;
49
49
50
50
/**
51
51
* Specifies which group an element in the input collection belongs to.
@@ -54,7 +54,7 @@ type Unary = ( value: any ) => string | symbol;
54
54
* @param index - collection index
55
55
* @returns object key
56
56
*/
57
- type Binary = ( value : any , index : number ) => string | symbol ;
57
+ type Binary < T > = ( value : T , index : number ) => string | symbol | number ;
58
58
59
59
/**
60
60
* Specifies which group an element in the input collection belongs to.
@@ -63,7 +63,17 @@ type Binary = ( value: any, index: number ) => string | symbol;
63
63
* @param index - collection index
64
64
* @returns object key
65
65
*/
66
- type Indicator = Nullary | Unary | Binary ;
66
+ type Indicator < T > = Nullary | Unary < T > | Binary < T > ;
67
+
68
+ /**
69
+ * Interface describing returned results.
70
+ */
71
+ interface Results < T > {
72
+ /**
73
+ * Object properties.
74
+ */
75
+ [ key : string | symbol | number ] : T ;
76
+ }
67
77
68
78
/**
69
79
* Groups values according to an indicator function and returns group counts.
@@ -92,7 +102,7 @@ type Indicator = Nullary | Unary | Binary;
92
102
* var out = countBy( arr, indicator );
93
103
* // returns { 'b': 3, 'f': 1 }
94
104
*/
95
- declare function countBy ( collection : Collection , indicator : Indicator ) : any ;
105
+ declare function countBy < T > ( collection : Collection < T > , indicator : Indicator < T > ) : Results < T > ;
96
106
97
107
/**
98
108
* Groups values according to an indicator function and returns group counts.
@@ -123,7 +133,7 @@ declare function countBy( collection: Collection, indicator: Indicator ): any;
123
133
* var out = countBy( arr, indicator );
124
134
* // returns { 'b': 3, 'f': 1 }
125
135
*/
126
- declare function countBy ( collection : Collection , options : Options , indicator : Indicator ) : any ; // tslint-disable-line max-line-length
136
+ declare function countBy < T > ( collection : Collection < T > , options : Options , indicator : Indicator < T > ) : Results < T > ;
127
137
128
138
129
139
// EXPORTS //
0 commit comments