Skip to content

Commit 8ab1051

Browse files
committed
feat!: refactor declarations to use generics
1 parent f15f90b commit 8ab1051

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

lib/node_modules/@stdlib/iter/to-array-view/docs/types/index.d.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,30 @@
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 { Iterator as Iter, IterableIterator } from '@stdlib/types/iter';
24-
import { ArrayLike } from '@stdlib/types/array';
23+
import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter';
2524
import { Collection } from '@stdlib/types/object';
2625

2726
// Define a union type representing both iterable and non-iterable iterators:
28-
type Iterator = Iter | IterableIterator;
27+
type Iterator<T> = TypedIterator<T> | TypedIterableIterator<T>;
2928

3029
/**
3130
* Map function invoked for each iterated value.
3231
*
3332
* @returns iterator value
3433
*/
35-
type Nullary = () => any;
34+
type Nullary<U> = () => U;
3635

3736
/**
3837
* Map function invoked for each iterated value.
3938
*
4039
* @param value - iterated value
4140
* @returns iterator value
4241
*/
43-
type Unary = ( value: any ) => any;
42+
type Unary<T, U> = ( value: T ) => U;
4443

4544
/**
4645
* Map function invoked for each iterated value.
@@ -49,7 +48,7 @@ type Unary = ( value: any ) => any;
4948
* @param index - iterated value index
5049
* @returns iterator value
5150
*/
52-
type Binary = ( value: any, index: number ) => any;
51+
type Binary<T, U> = ( value: T, index: number ) => U;
5352

5453
/**
5554
* Map function invoked for each iterated value.
@@ -59,7 +58,7 @@ type Binary = ( value: any, index: number ) => any;
5958
* @param src - source array-like object
6059
* @returns iterator value
6160
*/
62-
type Ternary = ( value: any, index: number, src: ArrayLike<any> ) => any;
61+
type Ternary<T, U> = ( value: T, index: number, src: Collection<U> ) => U;
6362

6463
/**
6564
* Map function invoked for each iterated value.
@@ -69,7 +68,7 @@ type Ternary = ( value: any, index: number, src: ArrayLike<any> ) => any;
6968
* @param src - source array-like object
7069
* @returns iterator value
7170
*/
72-
type MapFunction = Nullary | Unary | Binary | Ternary;
71+
type MapFunction<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U>;
7372

7473
/**
7574
* Fills an array-like object view with values returned from an iterator.
@@ -91,7 +90,7 @@ type MapFunction = Nullary | Unary | Binary | Ternary;
9190
* var arr = iterator2arrayview( iter, new Float64Array( 20 ) );
9291
* // returns <Float64Array>
9392
*/
94-
declare function iterator2arrayview( iterator: Iterator, out: Collection, mapFcn?: MapFunction, thisArg?: any ): Collection; // tslint:disable-line:max-line-length
93+
declare function iterator2arrayview<T = any, U = T>( iterator: Iterator<T>, out: Collection<U>, mapFcn?: MapFunction<T, U>, thisArg?: any ): Collection<U>; // tslint:disable-line:max-line-length
9594

9695
/**
9796
* Fills an array-like object view with values returned from an iterator.
@@ -114,7 +113,7 @@ declare function iterator2arrayview( iterator: Iterator, out: Collection, mapFcn
114113
* var arr = iterator2arrayview( iter, new Float64Array( 20 ), 5 );
115114
* // returns <Float64Array>
116115
*/
117-
declare function iterator2arrayview( iterator: Iterator, out: Collection, begin: number, mapFcn?: MapFunction, thisArg?: any ): Collection; // tslint:disable-line:max-line-length
116+
declare function iterator2arrayview<T = any, U = T>( iterator: Iterator<T>, out: Collection<U>, begin: number, mapFcn?: MapFunction<T, U>, thisArg?: any ): Collection<U>; // tslint:disable-line:max-line-length
118117

119118
/**
120119
* Fills an array-like object view with values returned from an iterator.
@@ -138,7 +137,7 @@ declare function iterator2arrayview( iterator: Iterator, out: Collection, begin:
138137
* var arr = iterator2arrayview( iter, new Float64Array( 20 ), 5, 8 );
139138
* // returns <Float64Array>
140139
*/
141-
declare function iterator2arrayview( iterator: Iterator, out: Collection, begin: number, end: number, mapFcn?: MapFunction, thisArg?: any ): Collection; // tslint:disable-line:max-line-length
140+
declare function iterator2arrayview<T = any, U = T>( iterator: Iterator<T>, out: Collection<U>, begin: number, end: number, mapFcn?: MapFunction<T, U>, thisArg?: any ): Collection<U>; // tslint:disable-line:max-line-length
142141

143142

144143
// EXPORTS //

lib/node_modules/@stdlib/iter/to-array-view/docs/types/test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ function times10( v: number ): number {
3636
{
3737
const iter = randu( { 'iter': 10 } );
3838
const out = new Float64Array( 10 );
39-
iterator2arrayview( iter, out ); // $ExpectType Collection
40-
iterator2arrayview( iter, out, times10 ); // $ExpectType Collection
41-
iterator2arrayview( iter, out, times10, {} ); // $ExpectType Collection
42-
iterator2arrayview( iter, out, 0, 10, times10 ); // $ExpectType Collection
43-
iterator2arrayview( iter, out, 0, 10, times10, {} ); // $ExpectType Collection
39+
iterator2arrayview( iter, out ); // $ExpectType Collection<number>
40+
iterator2arrayview( iter, out, times10 ); // $ExpectType Collection<number>
41+
iterator2arrayview( iter, out, times10, {} ); // $ExpectType Collection<number>
42+
iterator2arrayview( iter, out, 0, 10, times10 ); // $ExpectType Collection<number>
43+
iterator2arrayview( iter, out, 0, 10, times10, {} ); // $ExpectType Collection<number>
4444
}
4545

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

0 commit comments

Comments
 (0)