Skip to content

Commit a151e17

Browse files
committed
fix: update import path for Collection type definition
Ref: bde4671
1 parent 73b6076 commit a151e17

File tree

2 files changed

+40
-31
lines changed

2 files changed

+40
-31
lines changed

lib/node_modules/@stdlib/utils/do-while-each-right/docs/types/index.d.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
* limitations under the License.
1717
*/
1818

19-
// TypeScript Version: 2.0
19+
// TypeScript Version: 4.1
2020

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

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

2525
/**
2626
* Checks whether an element in a collection passes a test.
@@ -35,7 +35,7 @@ type NullaryPredicate = () => boolean;
3535
* @param value - collection value
3636
* @returns boolean indicating whether an element in a collection passes a test
3737
*/
38-
type UnaryPredicate = ( value: any ) => boolean;
38+
type UnaryPredicate<T> = ( value: T ) => boolean;
3939

4040
/**
4141
* Checks whether an element in a collection passes a test.
@@ -44,7 +44,7 @@ type UnaryPredicate = ( value: any ) => boolean;
4444
* @param index - collection index
4545
* @returns boolean indicating whether an element in a collection passes a test
4646
*/
47-
type BinaryPredicate = ( value: any, index: number ) => boolean;
47+
type BinaryPredicate<T> = ( value: T, index: number ) => boolean;
4848

4949
/**
5050
* Checks whether an element in a collection passes a test.
@@ -54,7 +54,7 @@ type BinaryPredicate = ( value: any, index: number ) => boolean;
5454
* @param collection - input collection
5555
* @returns boolean indicating whether an element in a collection passes a test
5656
*/
57-
type TernaryPredicate = ( value: any, index: number, collection: Collection ) => boolean; // tslint-disable-line max-line-length
57+
type TernaryPredicate<T> = ( value: T, index: number, collection: Collection ) => boolean;
5858

5959
/**
6060
* Checks whether an element in a collection passes a test.
@@ -64,7 +64,7 @@ type TernaryPredicate = ( value: any, index: number, collection: Collection ) =>
6464
* @param collection - input collection
6565
* @returns boolean indicating whether an element in a collection passes a test
6666
*/
67-
type Predicate = NullaryPredicate | UnaryPredicate | BinaryPredicate | TernaryPredicate; // tslint-disable-line max-line-length
67+
type Predicate<T> = NullaryPredicate | UnaryPredicate<T> | BinaryPredicate<T> | TernaryPredicate<T>;
6868

6969
/**
7070
* Function invoked for each collection element while a test condition is true.
@@ -76,15 +76,15 @@ type Nullary = () => void;
7676
*
7777
* @param value - collection value
7878
*/
79-
type Unary = ( value: any ) => void;
79+
type Unary<T> = ( value: T ) => void;
8080

8181
/**
8282
* Function invoked for each collection element while a test condition is true.
8383
*
8484
* @param value - collection value
8585
* @param index - collection index
8686
*/
87-
type Binary = ( value: any, index: number ) => void;
87+
type Binary<T> = ( value: T, index: number ) => void;
8888

8989
/**
9090
* Function invoked for each collection element while a test condition is true.
@@ -93,7 +93,7 @@ type Binary = ( value: any, index: number ) => void;
9393
* @param index - collection index
9494
* @param collection - input collection
9595
*/
96-
type Ternary = ( value: any, index: number, collection: Collection ) => void;
96+
type Ternary<T> = ( value: T, index: number, collection: Collection<T> ) => void;
9797

9898
/**
9999
* Function invoked for each collection element while a test condition is true.
@@ -102,7 +102,7 @@ type Ternary = ( value: any, index: number, collection: Collection ) => void;
102102
* @param index - collection index
103103
* @param collection - input collection
104104
*/
105-
type Callback = Nullary | Unary | Binary | Ternary;
105+
type Callback<T> = Nullary | Unary<T> | Binary<T> | Ternary<T>;
106106

107107
/**
108108
* While a test condition is true, invokes a function once for each element in a collection, iterating from right to left.
@@ -121,7 +121,6 @@ type Callback = Nullary | Unary | Binary | Ternary;
121121
*
122122
* - If provided an empty collection, the function invokes the provided function with the collection index set to `undefined`.
123123
*
124-
*
125124
* @param collection - input collection
126125
* @param fcn - function to invoke
127126
* @param predicate - function which indicates whether to continue iterating over a collection
@@ -141,7 +140,7 @@ type Callback = Nullary | Unary | Binary | Ternary;
141140
*
142141
* doWhileEachRight( arr, log, predicate );
143142
*/
144-
declare function doWhileEachRight( collection: Collection, fcn: Callback, predicate: Predicate, thisArg?: any ): Collection; // tslint-disable-line max-line-length
143+
declare function doWhileEachRight<T = unknown>( collection: Collection<T>, fcn: Callback<T>, predicate: Predicate<T>, thisArg?: ThisParameterType<Callback<T>> ): Collection<T>;
145144

146145

147146
// EXPORTS //

lib/node_modules/@stdlib/utils/do-while-each-right/docs/types/test.ts

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,38 @@
1818

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

21-
const log = ( v: any, index: number ): void => {
22-
console.log( `${index}: ${v}` );
23-
};
21+
/**
22+
* Dummy function.
23+
*/
24+
function fcn( v: any, index: number ): number {
25+
if ( v !== v ) {
26+
throw new Error( 'beep' );
27+
}
28+
return index;
29+
}
2430

25-
const isNotNaN = ( v: number ): boolean => {
31+
/**
32+
* Dummy function.
33+
*/
34+
function isNotNaN( v: number ): boolean {
2635
return ( v === v );
27-
};
36+
}
37+
2838

2939
// TESTS //
3040

3141
// The function returns the input collection...
3242
{
33-
doWhileEachRight( [ 0, 1, 1, NaN, 2 ], log, isNotNaN ); // $ExpectType Collection
34-
doWhileEachRight( [ -1, 1, 2 ], log, isNotNaN, {} ); // $ExpectType Collection
43+
doWhileEachRight( [ 0, 1, 1, NaN, 2 ], fcn, isNotNaN ); // $ExpectType Collection<number>
44+
doWhileEachRight( [ -1, 1, 2 ], fcn, isNotNaN, {} ); // $ExpectType Collection<number>
3545
}
3646

3747
// The compiler throws an error if the function is provided a first argument which is not a collection...
3848
{
39-
doWhileEachRight( 2, log, isNotNaN ); // $ExpectError
40-
doWhileEachRight( false, log, isNotNaN ); // $ExpectError
41-
doWhileEachRight( true, log, isNotNaN ); // $ExpectError
42-
doWhileEachRight( {}, log, isNotNaN ); // $ExpectError
49+
doWhileEachRight( 2, fcn, isNotNaN ); // $ExpectError
50+
doWhileEachRight( false, fcn, isNotNaN ); // $ExpectError
51+
doWhileEachRight( true, fcn, isNotNaN ); // $ExpectError
52+
doWhileEachRight( {}, fcn, isNotNaN ); // $ExpectError
4353
}
4454

4555
// The compiler throws an error if the function is provided a second argument which is not a function...
@@ -54,18 +64,18 @@ const isNotNaN = ( v: number ): boolean => {
5464

5565
// The compiler throws an error if the function is provided a third argument which is not a function...
5666
{
57-
doWhileEachRight( [ 0, 1, 1, NaN, 2 ], log, 2 ); // $ExpectError
58-
doWhileEachRight( [ 0, 1, 1, NaN, 2 ], log, false ); // $ExpectError
59-
doWhileEachRight( [ 0, 1, 1, NaN, 2 ], log, true ); // $ExpectError
60-
doWhileEachRight( [ 0, 1, 1, NaN, 2 ], log, 'abc' ); // $ExpectError
61-
doWhileEachRight( [ 0, 1, 1, NaN, 2 ], log, {} ); // $ExpectError
62-
doWhileEachRight( [ 0, 1, 1, NaN, 2 ], log, [] ); // $ExpectError
67+
doWhileEachRight( [ 0, 1, 1, NaN, 2 ], fcn, 2 ); // $ExpectError
68+
doWhileEachRight( [ 0, 1, 1, NaN, 2 ], fcn, false ); // $ExpectError
69+
doWhileEachRight( [ 0, 1, 1, NaN, 2 ], fcn, true ); // $ExpectError
70+
doWhileEachRight( [ 0, 1, 1, NaN, 2 ], fcn, 'abc' ); // $ExpectError
71+
doWhileEachRight( [ 0, 1, 1, NaN, 2 ], fcn, {} ); // $ExpectError
72+
doWhileEachRight( [ 0, 1, 1, NaN, 2 ], fcn, [] ); // $ExpectError
6373
}
6474

6575
// The compiler throws an error if the function is provided an invalid number of arguments...
6676
{
6777
doWhileEachRight(); // $ExpectError
6878
doWhileEachRight( [ 1, 2, 3 ] ); // $ExpectError
69-
doWhileEachRight( [ 1, 2, 3 ], log ); // $ExpectError
70-
doWhileEachRight( [ 1, 2, 3 ], log, isNotNaN, {}, 3 ); // $ExpectError
79+
doWhileEachRight( [ 1, 2, 3 ], fcn ); // $ExpectError
80+
doWhileEachRight( [ 1, 2, 3 ], fcn, isNotNaN, {}, 3 ); // $ExpectError
7181
}

0 commit comments

Comments
 (0)