Skip to content

Commit edcd742

Browse files
committed
feat!: convert Collection to generic
This commit converts `Collection` to a generic in order to better preserve type information. One example is when returning an element from a collection and wanting to preserve the returned element's type information. This change depends on default types, support for which was added in TypeScript version 2.3, which is beyond the current project support version of 2.0. Accordingly, this commit increases the minimum TypeScript version and sets that version to 4.1, which should include most new TypeScript features that we want to use in TypeScript declarations moving forward. BREAKING CHANGE: `Collection` is now a generic To migrate, users should upgrade their TypeScript version and provide element type information when using the `Collection` type (e.g., `Collection<number>`). By default, the element type is `any` which is equivalent to previous behavior.
1 parent 3628a1f commit edcd742

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/node_modules/@stdlib/types/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* limitations under the License.
1919
*/
2020

21-
// TypeScript Version: 2.0
21+
// TypeScript Version: 4.1
2222

2323
/**
2424
* Module containing array definitions.
@@ -2399,9 +2399,9 @@ declare module '@stdlib/types/object' {
23992399
* A collection, which is defined as either an array, typed array, or an array-like object (excluding strings and functions).
24002400
*
24012401
* @example
2402-
* const arr: Collection = [ 1, 2, 3 ];
2402+
* const arr: Collection<number> = [ 1, 2, 3 ];
24032403
*/
2404-
type Collection = Array<any> | TypedArray | ArrayLike<any>;
2404+
type Collection<T = any> = Array<T> | TypedArray | ArrayLike<T>;
24052405

24062406
/**
24072407
* Complex number data type.

lib/node_modules/@stdlib/types/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ function cmplx128Array(): array.Complex128Array {
484484
throw new Error( 'something went wrong' );
485485
}
486486

487-
const arr: obj.Collection = [ 1, 2, 3 ];
487+
const arr: obj.Collection<number> = [ 1, 2, 3 ];
488488
if ( arr.length !== 3 ) {
489489
throw new Error( 'something went wrong' );
490490
}

0 commit comments

Comments
 (0)