Skip to content

Commit

Permalink
fix: update import path for Collection type definition and use gene…
Browse files Browse the repository at this point in the history
…rics

Ref: bde4671
  • Loading branch information
kgryte committed Sep 10, 2023
1 parent e92aceb commit 724d386
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

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

import { Collection } from '@stdlib/types/object';
import { Collection } from '@stdlib/types/array';

/**
* Interface defining function options.
*/
interface Options {
interface Options<T, V> {
/**
* The maximum number of pending invocations at any one time.
*/
Expand All @@ -39,7 +39,7 @@ interface Options {
/**
* Execution context.
*/
thisArg?: any;
thisArg?: ThisParameterType<Predicate<T, V>>;
}

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

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

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

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

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

/**
* Interface for `anyByRightAsync`.
Expand All @@ -127,7 +127,6 @@ interface AnyByRightAsync {
* - 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.
* - 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`).
*
*
* @param collection - input collection
* @param options - function options
* @param options.thisArg - execution context
Expand Down Expand Up @@ -172,7 +171,7 @@ interface AnyByRightAsync {
*
* anyByRightAsync( files, predicate, done );
*/
( collection: Collection, options: Options, predicate: Predicate, done: Callback ): void; // tslint-disable-line max-line-length
<T = unknown, V = unknown>( collection: Collection<T>, options: Options<T, V>, predicate: Predicate<T, V>, done: Callback ): void;

/**
* Tests whether at least one element in a collection passes a test implemented by a predicate function, iterating from right to left.
Expand All @@ -182,7 +181,6 @@ interface AnyByRightAsync {
* - 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.
* - 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`).
*
*
* @param collection - input collection
* @param predicate - predicate function to invoke for each element in a collection
* @param done - function to invoke upon completion
Expand Down Expand Up @@ -222,7 +220,7 @@ interface AnyByRightAsync {
*
* anyByRightAsync( files, predicate, done );
*/
( collection: Collection, predicate: Predicate, done: Callback ): void;
<T = unknown, V = unknown>( collection: Collection<T>, predicate: Predicate<T, V>, done: Callback ): void; // tslint:disable-line:no-unnecessary-generics

/**
* 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.
Expand All @@ -232,7 +230,6 @@ interface AnyByRightAsync {
* - 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.
* - 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`).
*
*
* @param options - function options
* @param options.thisArg - execution context
* @param options.limit - maximum number of pending invocations at any one time
Expand Down Expand Up @@ -286,7 +283,7 @@ interface AnyByRightAsync {
* // Try to read each element in `files`:
* anyByRightAsync( files, done );
*/
factory( options: Options, predicate: Predicate ): FactoryFunction;
factory<T = unknown, V = unknown>( options: Options<T, V>, predicate: Predicate<T, V> ): FactoryFunction<T>;

/**
* 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.
Expand All @@ -296,7 +293,6 @@ interface AnyByRightAsync {
* - 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.
* - 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`).
*
*
* @param predicate - predicate function to invoke for each element in a collection
* @returns function which invokes the predicate function once for each element in a collection
*
Expand Down Expand Up @@ -340,7 +336,7 @@ interface AnyByRightAsync {
* // Try to read each element in `files`:
* anyByRightAsync( files, done );
*/
factory( predicate: Predicate ): FactoryFunction;
factory<T = unknown, V = unknown>( predicate: Predicate<T, V> ): FactoryFunction<T>; // tslint:disable-line:no-unnecessary-generics
}

/**
Expand All @@ -351,7 +347,6 @@ interface AnyByRightAsync {
* - 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.
* - 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`).
*
*
* @param collection - input collection
* @param options - function options
* @param options.thisArg - execution context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ const done = ( error: Error | null, bool: boolean ) => {

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

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

0 comments on commit 724d386

Please sign in to comment.