Skip to content

Commit bde4671

Browse files
committed
feat!: move Collection type defn to array type module
This commit addresses an awkward inconsistency in which a `Collection` was included in the `object` type module, despite being defined as a union of `array` type definitions. By moving `Collection` into `array` we make the import of `Collection` more intuitive given its semantic relationship to array-like objects. BREAKING CHANGE: move `Collection` type defn to array type module To migrate, users should import `@stdlib/types/array` instead of `@stdlib/types/object` when using the `Collection` type definition.
1 parent 32a2827 commit bde4671

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ declare module '@stdlib/types/array' {
150150
* @example
151151
* const x: Array1D<number> = [ 1, 2, 3, 4 ];
152152
*/
153-
type Array1D<T> = Array<T>; // FIXME: this should be a collection and should be updated once `Collection` is moved to the array namespace
153+
type Array1D<T> = Collection<T>;
154154

155155
/**
156156
* A two-dimensional nested array.
@@ -525,6 +525,14 @@ declare module '@stdlib/types/array' {
525525
*/
526526
set( value: ArrayLike<number | ComplexLike> | Complex128Array | ComplexLike, i?: number ): void;
527527
}
528+
529+
/**
530+
* A collection, which is defined as either an array, typed array, or an array-like object (excluding strings and functions).
531+
*
532+
* @example
533+
* const x: Collection<number> = [ 1, 2, 3 ];
534+
*/
535+
type Collection<T = any> = Array<T> | TypedArray | ArrayLike<T>;
528536
}
529537

530538
/**
@@ -732,9 +740,8 @@ declare module '@stdlib/types/iter' {
732740
* };
733741
*/
734742
declare module '@stdlib/types/ndarray' {
735-
import { ArrayLike, AccessorArrayLike, Complex128Array, Complex64Array, RealOrComplexTypedArray, FloatOrComplexTypedArray, RealTypedArray, ComplexTypedArray, IntegerTypedArray, FloatTypedArray, SignedIntegerTypedArray, UnsignedIntegerTypedArray } from '@stdlib/types/array';
743+
import { ArrayLike, AccessorArrayLike, Collection, Complex128Array, Complex64Array, RealOrComplexTypedArray, FloatOrComplexTypedArray, RealTypedArray, ComplexTypedArray, IntegerTypedArray, FloatTypedArray, SignedIntegerTypedArray, UnsignedIntegerTypedArray } from '@stdlib/types/array';
736744
import { ComplexLike, Complex128, Complex64 } from '@stdlib/types/complex';
737-
import { Collection } from '@stdlib/types/object';
738745

739746
/**
740747
* Data type.
@@ -2511,14 +2518,6 @@ declare module '@stdlib/types/object' {
25112518
* const prop: PropertyName = 'foo';
25122519
*/
25132520
type PropertyName = string | symbol;
2514-
2515-
/**
2516-
* A collection, which is defined as either an array, typed array, or an array-like object (excluding strings and functions).
2517-
*
2518-
* @example
2519-
* const x: Collection<number> = [ 1, 2, 3 ];
2520-
*/
2521-
type Collection<T = any> = Array<T> | TypedArray | ArrayLike<T>;
25222521
}
25232522

25242523
/**

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ function cmplx128Array(): array.Complex128Array {
355355
if ( v31.length === 0 ) {
356356
throw new Error( 'something went wrong' );
357357
}
358+
359+
const v32: array.Collection<number> = [ 1, 2, 3 ];
360+
if ( v32.length !== 3 ) {
361+
throw new Error( 'something went wrong' );
362+
}
358363
}
359364

360365
// The compiler should not throw an error when using iterator or iterable types...
@@ -534,11 +539,6 @@ function cmplx128Array(): array.Complex128Array {
534539
if ( prop !== 'foo' ) {
535540
throw new Error( 'something went wrong' );
536541
}
537-
538-
const arr: obj.Collection<number> = [ 1, 2, 3 ];
539-
if ( arr.length !== 3 ) {
540-
throw new Error( 'something went wrong' );
541-
}
542542
}
543543

544544
// The compiler should not throw an error when using complex number types...

0 commit comments

Comments
 (0)