Skip to content

Commit 08b8c12

Browse files
committed
feat!: refactor declarations to use generics
1 parent e1daa17 commit 08b8c12

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

lib/node_modules/@stdlib/array/base/accessors/docs/types/index.d.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

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

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

@@ -130,7 +130,7 @@ type GetComplex64 = ( arr: Complex64Array, idx: number ) => Complex64 | void;
130130
* @param idx - element index
131131
* @returns element value
132132
*/
133-
type GetGeneric = ( arr: Array<any>, idx: number ) => any;
133+
type GetGeneric<T> = ( arr: Array<T>, idx: number ) => T;
134134

135135
/**
136136
* Returns an element from an indexed array-like object.
@@ -139,7 +139,7 @@ type GetGeneric = ( arr: Array<any>, idx: number ) => any;
139139
* @param idx - element index
140140
* @returns element value
141141
*/
142-
type GetIndexedArrayLike = ( arr: Collection, idx: number ) => any;
142+
type GetIndexedArrayLike<T> = ( arr: Collection<T>, idx: number ) => T;
143143

144144
/**
145145
* Returns an element from an array-like object supporting the get/set protocol.
@@ -148,7 +148,7 @@ type GetIndexedArrayLike = ( arr: Collection, idx: number ) => any;
148148
* @param idx - element index
149149
* @returns element value
150150
*/
151-
type GetAccessorArrayLike = ( arr: AccessorArrayLike<any>, idx: number ) => any;
151+
type GetAccessorArrayLike<T> = ( arr: AccessorArrayLike<T>, idx: number ) => T;
152152

153153
/**
154154
* Sets an element in a `Float64Array`.
@@ -256,7 +256,7 @@ type SetComplex64 = ( arr: Complex64Array, idx: number, value: ComplexLike ) =>
256256
* @param idx - element index
257257
* @param value - value to set
258258
*/
259-
type SetGeneric = ( arr: Array<any>, idx: number, value: any ) => void;
259+
type SetGeneric<T> = ( arr: Array<T>, idx: number, value: T ) => void;
260260

261261
/**
262262
* Sets an element in an indexed array-like object.
@@ -265,7 +265,7 @@ type SetGeneric = ( arr: Array<any>, idx: number, value: any ) => void;
265265
* @param idx - element index
266266
* @param value - value to set
267267
*/
268-
type SetIndexedArrayLike = ( arr: Collection, idx: number, value: any ) => void;
268+
type SetIndexedArrayLike<T> = ( arr: Collection<T>, idx: number, value: T ) => void; // tslint:disable-line:max-line-length
269269

270270
/**
271271
* Sets an element in an array-like object supporting the get/set protocol.
@@ -274,7 +274,7 @@ type SetIndexedArrayLike = ( arr: Collection, idx: number, value: any ) => void;
274274
* @param idx - element index
275275
* @param value - value to set
276276
*/
277-
type SetAccessorArrayLike = ( arr: AccessorArrayLike<any>, idx: number, value: any ) => void; // tslint:disable-line:max-line-length
277+
type SetAccessorArrayLike<T> = ( arr: AccessorArrayLike<T>, idx: number, value: T ) => void; // tslint:disable-line:max-line-length
278278

279279
/**
280280
* Interface describing the output object for a `Float64Array`.
@@ -444,7 +444,7 @@ interface Complex64AccessorObject {
444444
/**
445445
* Interface describing the output object for a "generic" array not supporting the get/set protocol.
446446
*/
447-
interface GenericAccessorObject {
447+
interface GenericAccessorObject<T> {
448448
/**
449449
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
450450
*/
@@ -453,13 +453,13 @@ interface GenericAccessorObject {
453453
/**
454454
* Two-element array whose first element is an accessor for retrieving an array element and whose second element is an accessor for setting an array element.
455455
*/
456-
accessors: [ GetGeneric, SetGeneric ];
456+
accessors: [ GetGeneric<T>, SetGeneric<T> ];
457457
}
458458

459459
/**
460460
* Interface describing the output object for an indexed array-like object.
461461
*/
462-
interface IndexedAccessorObject {
462+
interface IndexedAccessorObject<T> {
463463
/**
464464
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
465465
*/
@@ -468,13 +468,13 @@ interface IndexedAccessorObject {
468468
/**
469469
* Two-element array whose first element is an accessor for retrieving an array element and whose second element is an accessor for setting an array element.
470470
*/
471-
accessors: [ GetIndexedArrayLike, SetIndexedArrayLike ];
471+
accessors: [ GetIndexedArrayLike<T>, SetIndexedArrayLike<T> ];
472472
}
473473

474474
/**
475475
* Interface describing the output object for an array-like object supporting the get/set protocol.
476476
*/
477-
interface GetSetAccessorObject {
477+
interface GetSetAccessorObject<T> {
478478
/**
479479
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
480480
*/
@@ -483,7 +483,7 @@ interface GetSetAccessorObject {
483483
/**
484484
* Two-element array whose first element is an accessor for retrieving an array element and whose second element is an accessor for setting an array element.
485485
*/
486-
accessors: [ GetAccessorArrayLike, SetAccessorArrayLike ];
486+
accessors: [ GetAccessorArrayLike<T>, SetAccessorArrayLike<T> ];
487487
}
488488

489489
/**
@@ -830,7 +830,7 @@ declare function accessors( x: Complex64Array ): Complex64AccessorObject;
830830
* var v = fcns[ 0 ]( x, 2 );
831831
* // returns 3
832832
*/
833-
declare function accessors( x: AccessorArrayLike<any> ): GetSetAccessorObject;
833+
declare function accessors<T = any>( x: AccessorArrayLike<T> ): GetSetAccessorObject<T>; // tslint:disable-line:max-line-length
834834

835835
/**
836836
* Returns element accessors for a provided "generic" array.
@@ -856,7 +856,7 @@ declare function accessors( x: AccessorArrayLike<any> ): GetSetAccessorObject;
856856
* var v = fcns[ 0 ]( x, 2 );
857857
* // returns 3
858858
*/
859-
declare function accessors( x: Array<any> ): GenericAccessorObject;
859+
declare function accessors<T = any>( x: Array<T> ): GenericAccessorObject<T>;
860860

861861
/**
862862
* Returns element accessors for a provided array-like object.
@@ -888,7 +888,7 @@ declare function accessors( x: Array<any> ): GenericAccessorObject;
888888
* var v = fcns[ 0 ]( x, 2 );
889889
* // returns 3
890890
*/
891-
declare function accessors( x: Collection ): IndexedAccessorObject;
891+
declare function accessors<T = any>( x: Collection<T> ): IndexedAccessorObject<T>; // tslint:disable-line:max-line-length
892892

893893

894894
// EXPORTS //

lib/node_modules/@stdlib/array/base/accessors/docs/types/test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function arrayLike(): ArrayLike<number> {
6969
// The function returns an accessor object...
7070
{
7171
const x1 = [ 1, 2, 3, 4, 5, 6 ];
72-
accessors( x1 ); // $ExpectType GenericAccessorObject
72+
accessors( x1 ); // $ExpectType GenericAccessorObject<number>
7373

7474
const x2 = new Float64Array( [ 1, 2, 3, 4, 5, 6 ] );
7575
accessors( x2 ); // $ExpectType Float64AccessorObject
@@ -105,10 +105,10 @@ function arrayLike(): ArrayLike<number> {
105105
accessors( x12 ); // $ExpectType Complex64AccessorObject
106106

107107
const x13 = accessorArray();
108-
accessors( x13 ); // $ExpectType GetSetAccessorObject
108+
accessors( x13 ); // $ExpectType GetSetAccessorObject<number>
109109

110110
const x14 = arrayLike();
111-
accessors( x14 ); // $ExpectType IndexedAccessorObject
111+
accessors( x14 ); // $ExpectType IndexedAccessorObject<number>
112112
}
113113

114114
// The compiler throws an error if the function is not provided an array-like object...

0 commit comments

Comments
 (0)