Skip to content

Commit fe37cac

Browse files
committed
feat: improve type specificity by converting to generic
1 parent 487d98c commit fe37cac

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/node_modules/@stdlib/array/base/filled-by/docs/types/index.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@
2323
*
2424
* @returns fill value
2525
*/
26-
type Nullary = () => any;
26+
type Nullary<T, U> = ( this: U ) => T;
2727

2828
/**
2929
* Unary callback function.
3030
*
3131
* @param i - current array index
3232
* @returns fill value
3333
*/
34-
type Unary = ( i: number ) => any;
34+
type Unary<T, U> = ( this: U, i: number ) => T;
3535

3636
/**
3737
* Callback function.
3838
*
3939
* @param i - current array index
4040
* @returns fill value
4141
*/
42-
type Callback = Nullary | Unary;
42+
type Callback<T, U> = Nullary<T, U> | Unary<T, U>;
4343

4444
/**
4545
* Returns a filled "generic" array according to a provided callback function.
@@ -55,7 +55,7 @@ type Callback = Nullary | Unary;
5555
* var arr = filledBy( 5, constantFunction( 1.0 ) );
5656
* // returns [ 1.0, 1.0, 1.0, 1.0, 1.0 ]
5757
*/
58-
declare function filledBy( len: number, clbk: Callback, thisArg?: any ): Array<any>; // tslint:disable-line:max-line-length
58+
declare function filledBy<T = unknown, U = unknown>( len: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): Array<T>;
5959

6060

6161
// EXPORTS //

lib/node_modules/@stdlib/array/base/filled-by/docs/types/test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ function clbk( i: number ): number {
3333

3434
// The function returns an array...
3535
{
36-
filledBy( 3, clbk ); // $ExpectType any[]
37-
filledBy( 3, clbk, {} ); // $ExpectType any[]
36+
filledBy( 3, clbk ); // $ExpectType number[]
37+
filledBy( 3, clbk, {} ); // $ExpectType number[]
3838
}
3939

4040
// The compiler throws an error if the function is provided a first argument which is not a number...

0 commit comments

Comments
 (0)