Skip to content

Commit 5573a67

Browse files
committed
fix: update import path for Collection type definition and use generics
Ref: bde4671
1 parent 447a49d commit 5573a67

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

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

+34-29
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
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.
2727
*/
28-
interface Options {
28+
interface Options<T, V> {
2929
/**
3030
* The maximum number of pending invocations at any one time.
3131
*/
@@ -39,72 +39,82 @@ interface Options {
3939
/**
4040
* Execution context.
4141
*/
42-
thisArg?: any;
42+
thisArg?: ThisParameterType<Indicator<T, V>>;
43+
}
44+
45+
/**
46+
* Interface defining a results object.
47+
*/
48+
interface Results {
49+
/**
50+
* Results for an individual group.
51+
*/
52+
[ key: string ]: number;
4353
}
4454

4555
/**
4656
* Callback invoked either upon processing all collection elements or upon encountering an error.
4757
*/
48-
type DoneNullary = () => void;
58+
type Nullary = () => void;
4959

5060
/**
5161
* Callback invoked either upon processing all collection elements or upon encountering an error.
5262
*
5363
* @param error - encountered error or null
5464
*/
55-
type DoneUnary = ( error: Error | null ) => void;
65+
type Unary = ( error: Error | null ) => void;
5666

5767
/**
5868
* Callback invoked either upon processing all collection elements or upon encountering an error.
5969
*
6070
* @param error - encountered error or null
6171
* @param result - counts
6272
*/
63-
type DoneBinary = ( error: Error | null, result: any ) => void;
73+
type Binary = ( error: Error | null, result: Results ) => void;
6474

6575
/**
6676
* Callback invoked either upon processing all collection elements or upon encountering an error.
6777
*
6878
* @param error - encountered error or null
6979
* @param result - counts
7080
*/
71-
type DoneCallback = DoneNullary | DoneUnary | DoneBinary;
81+
type Callback = Nullary | Unary | Binary;
7282

7383
/**
74-
* Callback function.
84+
* Callback function to invoke once the predicate function has finished processing a collection value.
7585
*/
76-
type Nullary = () => void;
86+
type NullaryNext = () => void;
7787

7888
/**
79-
* Callback function.
89+
* Callback function to invoke once the predicate function has finished processing a collection value.
8090
*
8191
* @param error - encountered error or null
8292
*/
83-
type Unary = ( error: Error | null ) => void;
93+
type UnaryNext = ( error: Error | null ) => void;
8494

8595
/**
86-
* Callback function.
96+
* Callback function to invoke once the predicate function has finished processing a collection value.
8797
*
8898
* @param error - encountered error or null
8999
* @param group - value group
90100
*/
91-
type Binary = ( error: Error | null, group: string ) => void;
101+
type BinaryNext = ( error: Error | null, group: string | Symbol | number ) => void;
92102

93103
/**
94-
* Callback function.
104+
* Callback function to invoke once the predicate function has finished processing a collection value.
95105
*
96106
* @param error - encountered error or null
97107
* @param group - value group
98108
*/
99-
type Callback = Nullary | Unary | Binary;
109+
type Next = NullaryNext | UnaryNext | BinaryNext;
100110

101111
/**
102112
* Checks whether an element in a collection passes a test.
103113
*
104114
* @param value - collection value
105115
* @param next - a callback to be invoked after processing a collection `value`
106116
*/
107-
type BinaryIndicator = ( value: any, next: Callback ) => void;
117+
type BinaryIndicator<T, V> = ( this: V, value: T, next: Next ) => void;
108118

109119
/**
110120
* Checks whether an element in a collection passes a test.
@@ -113,7 +123,7 @@ type BinaryIndicator = ( value: any, next: Callback ) => void;
113123
* @param index - collection index
114124
* @param next - a callback to be invoked after processing a collection `value`
115125
*/
116-
type TernaryIndicator = ( value: any, index: number, next: Callback ) => void;
126+
type TernaryIndicator<T, V> = ( this: V, value: T, index: number, next: Next ) => void;
117127

118128
/**
119129
* Checks whether an element in a collection passes a test.
@@ -123,7 +133,7 @@ type TernaryIndicator = ( value: any, index: number, next: Callback ) => void;
123133
* @param collection - input collection
124134
* @param next - a callback to be invoked after processing a collection `value`
125135
*/
126-
type QuaternaryIndicator = ( value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length
136+
type QuaternaryIndicator<T, V> = ( this: V, value: T, index: number, collection: Collection<T>, next: Next ) => void;
127137

128138
/**
129139
* Checks whether an element in a collection passes a test.
@@ -133,15 +143,15 @@ type QuaternaryIndicator = ( value: any, index: number, collection: Collection,
133143
* @param collection - input collection
134144
* @param next - a callback to be invoked after processing a collection `value`
135145
*/
136-
type Indicator = Unary | BinaryIndicator | TernaryIndicator | QuaternaryIndicator; // tslint-disable-line max-line-length
146+
type Indicator<T, V> = BinaryIndicator<T, V> | TernaryIndicator<T, V> | QuaternaryIndicator<T, V>;
137147

138148
/**
139149
* Invokes an indicator function for each element in a collection.
140150
*
141151
* @param collection - input collection
142152
* @param done - function to invoke upon completion
143153
*/
144-
type FactoryFunction = ( collection: Collection, done: DoneCallback ) => void;
154+
type FactoryFunction<T> = ( collection: Collection<T>, done: Callback ) => void;
145155

146156
/**
147157
* Interface for `countByAsync`.
@@ -154,7 +164,6 @@ interface CountByAsync {
154164
*
155165
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
156166
*
157-
*
158167
* @param collection - input collection
159168
* @param options - function options
160169
* @param options.thisArg - execution context
@@ -195,7 +204,7 @@ interface CountByAsync {
195204
*
196205
* countByAsync( files, indicator, done );
197206
*/
198-
( collection: Collection, options: Options, indicator: Indicator, done: DoneCallback ): void; // tslint-disable-line max-line-length
207+
<T = unknown, V = unknown>( collection: Collection<T>, options: Options<T, V>, indicator: Indicator<T, V>, done: Callback ): void;
199208

200209
/**
201210
* Groups values according to an indicator function and returns group counts.
@@ -204,7 +213,6 @@ interface CountByAsync {
204213
*
205214
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
206215
*
207-
*
208216
* @param collection - input collection
209217
* @param indicator - indicator function specifying which group an element in the input collection belongs to
210218
* @param done - function to invoke upon completion
@@ -241,7 +249,7 @@ interface CountByAsync {
241249
*
242250
* countByAsync( files, indicator, done );
243251
*/
244-
( collection: Collection, indicator: Indicator, done: DoneCallback ): void;
252+
<T = unknown, V = unknown>( collection: Collection<T>, indicator: Indicator<T, V>, done: Callback ): void; // tslint:disable-line:no-unnecessary-generics
245253

246254
/**
247255
* Returns a function for grouping values according to an indicator function and returns group counts.
@@ -250,7 +258,6 @@ interface CountByAsync {
250258
*
251259
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
252260
*
253-
*
254261
* @param options - function options
255262
* @param options.thisArg - execution context
256263
* @param options.limit - maximum number of pending invocations at any one time
@@ -300,7 +307,7 @@ interface CountByAsync {
300307
* // Try to read each element in `files`:
301308
* countByAsync( files, done );
302309
*/
303-
factory( options: Options, indicator: Indicator ): FactoryFunction;
310+
factory<T = unknown, V = unknown>( options: Options<T, V>, indicator: Indicator<T, V> ): FactoryFunction<T>;
304311

305312
/**
306313
* Returns a function for grouping values according to an indicator function and returns group counts.
@@ -309,7 +316,6 @@ interface CountByAsync {
309316
*
310317
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
311318
*
312-
*
313319
* @param options - function options
314320
* @param options.thisArg - execution context
315321
* @param options.limit - maximum number of pending invocations at any one time
@@ -355,7 +361,7 @@ interface CountByAsync {
355361
* // Try to read each element in `files`:
356362
* countByAsync( files, done );
357363
*/
358-
factory( indicator: Indicator ): FactoryFunction;
364+
factory<T = unknown, V = unknown>( indicator: Indicator<T, V> ): FactoryFunction<T>; // tslint:disable-line:no-unnecessary-generics
359365
}
360366

361367
/**
@@ -365,7 +371,6 @@ interface CountByAsync {
365371
*
366372
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
367373
*
368-
*
369374
* @param collection - input collection
370375
* @param options - function options
371376
* @param options.thisArg - execution context

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ const done = ( error: Error | null, result: any ) => {
106106

107107
// Attached to main export is a `factory` method which returns a function...
108108
{
109-
countByAsync.factory( indicator ); // $ExpectType FactoryFunction
110-
countByAsync.factory( { 'series': true }, indicator ); // $ExpectType FactoryFunction
109+
countByAsync.factory( indicator ); // $ExpectType FactoryFunction<number>
110+
countByAsync.factory( { 'series': true }, indicator ); // $ExpectType FactoryFunction<number>
111111
}
112112

113113
// The compiler throws an error if the `factory` method is provided an options argument which is not an object...

0 commit comments

Comments
 (0)