Skip to content

Commit 724d386

Browse files
committed
fix: update import path for Collection type definition and use generics
Ref: bde4671
1 parent e92aceb commit 724d386

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

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

+13-18
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,7 +39,7 @@ interface Options {
3939
/**
4040
* Execution context.
4141
*/
42-
thisArg?: any;
42+
thisArg?: ThisParameterType<Predicate<T, V>>;
4343
}
4444

4545
/**
@@ -76,7 +76,7 @@ type Callback = Nullary | Unary | Binary;
7676
* @param value - collection value
7777
* @param next - callback which should be called once the predicate function has finished processing a collection value
7878
*/
79-
type BinaryPredicate = ( value: any, next: Callback ) => void;
79+
type BinaryPredicate<T, V> = ( this: V, value: T, next: Callback ) => void;
8080

8181
/**
8282
* Checks whether an element in a collection passes a test.
@@ -85,7 +85,7 @@ type BinaryPredicate = ( value: any, next: Callback ) => void;
8585
* @param index - collection index
8686
* @param next - callback which should be called once the `predicate` function has finished processing a collection `value`
8787
*/
88-
type TernaryPredicate = ( value: any, index: number, next: Callback ) => void;
88+
type TernaryPredicate<T, V> = ( this: V, value: T, index: number, next: Callback ) => void;
8989

9090
/**
9191
* Checks whether an element in a collection passes a test.
@@ -95,7 +95,7 @@ type TernaryPredicate = ( value: any, index: number, next: Callback ) => void;
9595
* @param collection - input collection
9696
* @param next - callback which should be called once the `predicate` function has finished processing a collection `value`
9797
*/
98-
type QuaternaryPredicate = ( value: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length
98+
type QuaternaryPredicate<T, V> = ( this: V, value: T, index: number, collection: Collection<T>, next: Callback ) => void;
9999

100100
/**
101101
* Checks whether an element in a collection passes a test.
@@ -105,15 +105,15 @@ type QuaternaryPredicate = ( value: any, index: number, collection: Collection,
105105
* @param collection - input collection
106106
* @param next - callback which should be called once the `predicate` function has finished processing a collection `value`
107107
*/
108-
type Predicate = BinaryPredicate | TernaryPredicate | QuaternaryPredicate;
108+
type Predicate<T, V> = BinaryPredicate<T, V> | TernaryPredicate<T, V> | QuaternaryPredicate<T, V>;
109109

110110
/**
111-
* Tests whether at least one element in a collection passes a test implemented by a predicate function, iterating from right to left.
111+
* Tests whether at least one element in a collection passes a test implemented by a predicate function.
112112
*
113113
* @param collection - input collection
114114
* @param done - function to invoke upon completion
115115
*/
116-
type FactoryFunction = ( collection: Collection, done: Callback ) => void;
116+
type FactoryFunction<T> = ( collection: Collection<T>, done: Callback ) => void;
117117

118118
/**
119119
* Interface for `anyByRightAsync`.
@@ -127,7 +127,6 @@ interface AnyByRightAsync {
127127
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
128128
* - 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`).
129129
*
130-
*
131130
* @param collection - input collection
132131
* @param options - function options
133132
* @param options.thisArg - execution context
@@ -172,7 +171,7 @@ interface AnyByRightAsync {
172171
*
173172
* anyByRightAsync( files, predicate, done );
174173
*/
175-
( collection: Collection, options: Options, predicate: Predicate, done: Callback ): void; // tslint-disable-line max-line-length
174+
<T = unknown, V = unknown>( collection: Collection<T>, options: Options<T, V>, predicate: Predicate<T, V>, done: Callback ): void;
176175

177176
/**
178177
* Tests whether at least one element in a collection passes a test implemented by a predicate function, iterating from right to left.
@@ -182,7 +181,6 @@ interface AnyByRightAsync {
182181
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
183182
* - 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`).
184183
*
185-
*
186184
* @param collection - input collection
187185
* @param predicate - predicate function to invoke for each element in a collection
188186
* @param done - function to invoke upon completion
@@ -222,7 +220,7 @@ interface AnyByRightAsync {
222220
*
223221
* anyByRightAsync( files, predicate, done );
224222
*/
225-
( collection: Collection, predicate: Predicate, done: Callback ): void;
223+
<T = unknown, V = unknown>( collection: Collection<T>, predicate: Predicate<T, V>, done: Callback ): void; // tslint:disable-line:no-unnecessary-generics
226224

227225
/**
228226
* Returns a function for testing whether at least one element in a collection passes a test implemented by a predicate function, iterating from right to left.
@@ -232,7 +230,6 @@ interface AnyByRightAsync {
232230
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
233231
* - 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`).
234232
*
235-
*
236233
* @param options - function options
237234
* @param options.thisArg - execution context
238235
* @param options.limit - maximum number of pending invocations at any one time
@@ -286,7 +283,7 @@ interface AnyByRightAsync {
286283
* // Try to read each element in `files`:
287284
* anyByRightAsync( files, done );
288285
*/
289-
factory( options: Options, predicate: Predicate ): FactoryFunction;
286+
factory<T = unknown, V = unknown>( options: Options<T, V>, predicate: Predicate<T, V> ): FactoryFunction<T>;
290287

291288
/**
292289
* Returns a function for testing whether at least one element in a collection passes a test implemented by a predicate function, iterating from right to left.
@@ -296,7 +293,6 @@ interface AnyByRightAsync {
296293
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
297294
* - 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`).
298295
*
299-
*
300296
* @param predicate - predicate function to invoke for each element in a collection
301297
* @returns function which invokes the predicate function once for each element in a collection
302298
*
@@ -340,7 +336,7 @@ interface AnyByRightAsync {
340336
* // Try to read each element in `files`:
341337
* anyByRightAsync( files, done );
342338
*/
343-
factory( predicate: Predicate ): FactoryFunction;
339+
factory<T = unknown, V = unknown>( predicate: Predicate<T, V> ): FactoryFunction<T>; // tslint:disable-line:no-unnecessary-generics
344340
}
345341

346342
/**
@@ -351,7 +347,6 @@ interface AnyByRightAsync {
351347
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
352348
* - 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`).
353349
*
354-
*
355350
* @param collection - input collection
356351
* @param options - function options
357352
* @param options.thisArg - execution context

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ const done = ( error: Error | null, bool: boolean ) => {
7979

8080
// Attached to main export is a `factory` method which returns a function...
8181
{
82-
anyByRightAsync.factory( isPositive ); // $ExpectType FactoryFunction
83-
anyByRightAsync.factory( { 'series': true }, isPositive ); // $ExpectType FactoryFunction
82+
anyByRightAsync.factory( isPositive ); // $ExpectType FactoryFunction<number>
83+
anyByRightAsync.factory( { 'series': true }, isPositive ); // $ExpectType FactoryFunction<number>
8484
}
8585

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

0 commit comments

Comments
 (0)