Skip to content

Commit a5bc25a

Browse files
committed
fix: update import path for Collection type definition
Ref: bde4671
1 parent b423df5 commit a5bc25a

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

lib/node_modules/@stdlib/utils/count-by/docs/repl.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
When invoked, the indicator function is provided two arguments:
66

7-
- `value`: collection value
8-
- `index`: collection index
7+
- value: collection value
8+
- index: collection index
99

1010
The value returned by an indicator function should be a value which can be
1111
serialized as an object key.

lib/node_modules/@stdlib/utils/count-by/docs/types/index.d.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
/// <reference types="@stdlib/types"/>
2222

23-
import { Collection } from '@stdlib/types/object';
23+
import { Collection } from '@stdlib/types/array';
2424

2525
/**
2626
* Interface defining function options.
@@ -37,15 +37,15 @@ interface Options {
3737
*
3838
* @returns object key
3939
*/
40-
type Nullary = () => string | symbol;
40+
type Nullary = () => string | symbol | number;
4141

4242
/**
4343
* Specifies which group an element in the input collection belongs to.
4444
*
4545
* @param value - collection value
4646
* @returns object key
4747
*/
48-
type Unary = ( value: any ) => string | symbol;
48+
type Unary<T> = ( value: T ) => string | symbol | number;
4949

5050
/**
5151
* Specifies which group an element in the input collection belongs to.
@@ -54,7 +54,7 @@ type Unary = ( value: any ) => string | symbol;
5454
* @param index - collection index
5555
* @returns object key
5656
*/
57-
type Binary = ( value: any, index: number ) => string | symbol;
57+
type Binary<T> = ( value: T, index: number ) => string | symbol | number;
5858

5959
/**
6060
* Specifies which group an element in the input collection belongs to.
@@ -63,7 +63,17 @@ type Binary = ( value: any, index: number ) => string | symbol;
6363
* @param index - collection index
6464
* @returns object key
6565
*/
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+
}
6777

6878
/**
6979
* Groups values according to an indicator function and returns group counts.
@@ -92,7 +102,7 @@ type Indicator = Nullary | Unary | Binary;
92102
* var out = countBy( arr, indicator );
93103
* // returns { 'b': 3, 'f': 1 }
94104
*/
95-
declare function countBy( collection: Collection, indicator: Indicator ): any;
105+
declare function countBy<T>( collection: Collection<T>, indicator: Indicator<T> ): Results<T>;
96106

97107
/**
98108
* Groups values according to an indicator function and returns group counts.
@@ -123,7 +133,7 @@ declare function countBy( collection: Collection, indicator: Indicator ): any;
123133
* var out = countBy( arr, indicator );
124134
* // returns { 'b': 3, 'f': 1 }
125135
*/
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>;
127137

128138

129139
// EXPORTS //

lib/node_modules/@stdlib/utils/count-by/docs/types/test.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,28 @@
1818

1919
import countBy = require( './index' );
2020

21-
const indicator = ( v: string ): string => v[ 0 ];
21+
/**
22+
* Indicator function.
23+
*
24+
* @param v - value
25+
* @returns indicator
26+
*/
27+
function indicator( v: string ): string {
28+
return v[ 0 ];
29+
}
2230

2331

2432
// TESTS //
2533

2634
// The function returns an object...
2735
{
28-
countBy( [ 'beep', 'boop', 'foo', 'bar' ], indicator ); // $ExpectType any
29-
countBy( [], indicator ); // $ExpectType any
36+
countBy( [ 'beep', 'boop', 'foo', 'bar' ], indicator ); // $ExpectType Results<string>
37+
countBy( [], indicator ); // $ExpectType Results<string>
38+
3039
const opts = {
3140
'thisArg': {}
3241
};
33-
countBy( [ 'beep', 'boop', 'foo', 'bar' ], opts, indicator ); // $ExpectType any
42+
countBy( [ 'beep', 'boop', 'foo', 'bar' ], opts, indicator ); // $ExpectType Results<string>
3443
}
3544

3645
// The compiler throws an error if the function is provided a first argument which is not a collection...
@@ -43,6 +52,7 @@ const indicator = ( v: string ): string => v[ 0 ];
4352
// The compiler throws an error if the function is provided a last argument which is not a function...
4453
{
4554
const arr = [ 'beep', 'boop', 'foo', 'bar' ];
55+
4656
countBy( arr, false ); // $ExpectError
4757
countBy( arr, true ); // $ExpectError
4858
countBy( arr, 32 ); // $ExpectError
@@ -61,12 +71,14 @@ const indicator = ( v: string ): string => v[ 0 ];
6171
// The compiler throws an error if the function is provided an options argument which is not an object...
6272
{
6373
const arr = [ 'beep', 'boop', 'foo', 'bar' ];
74+
6475
countBy( arr, null, indicator ); // $ExpectError
6576
}
6677

6778
// The compiler throws an error if the function is provided an invalid number of arguments...
6879
{
6980
const arr = [ 'beep', 'boop', 'foo', 'bar' ];
81+
7082
countBy(); // $ExpectError
7183
countBy( arr ); // $ExpectError
7284
countBy( arr, {}, indicator, 16 ); // $ExpectError

0 commit comments

Comments
 (0)