Skip to content

Commit 2abd8cd

Browse files
committed
feat!: refactor declarations to use generics
1 parent ee49f1e commit 2abd8cd

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

lib/node_modules/@stdlib/array/base/n-cartesian-product/docs/types/index.d.ts

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

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

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

2323
import { Collection } from '@stdlib/types/object';
2424

25+
/**
26+
* Returns the n-fold Cartesian product.
27+
*
28+
* ## Notes
29+
*
30+
* - If provided one or more empty arrays, the function returns an empty array.
31+
*
32+
* @param x1 - first input array
33+
* @param x2 - second input array
34+
* @returns Cartesian product
35+
*
36+
* @example
37+
* var x1 = [ 1, 2, 3 ];
38+
* var x2 = [ 4, 5 ];
39+
*
40+
* var out = nCartesianProduct( x1, x2 );
41+
* // returns [ [ 1, 4 ], [ 1, 5 ], [ 2, 4 ], [ 2, 5 ], [ 3, 4 ], [ 3, 5 ] ]
42+
*/
43+
declare function nCartesianProduct<T = any, U = any>( x1: Collection<T>, x2: Collection<U> ): Array<[T, U]>; // tslint:disable-line:max-line-length
44+
45+
/**
46+
* Returns the n-fold Cartesian product.
47+
*
48+
* ## Notes
49+
*
50+
* - If provided one or more empty arrays, the function returns an empty array.
51+
*
52+
* @param x1 - first input array
53+
* @param x2 - second input array
54+
* @param x3 - third input array
55+
* @returns Cartesian product
56+
*
57+
* @example
58+
* var x1 = [ 1, 2, 3 ];
59+
* var x2 = [ 4, 5 ];
60+
* var x3 = [ 6 ];
61+
*
62+
* var out = nCartesianProduct( x1, x2, x3 );
63+
* // returns [ [ 1, 4, 6 ], [ 1, 5, 6 ], [ 2, 4, 6 ], [ 2, 5, 6 ], [ 3, 4, 6 ], [ 3, 5, 6 ] ]
64+
*/
65+
declare function nCartesianProduct<T = any, U = any, V = any>( x1: Collection<T>, x2: Collection<U>, x3: Collection<V> ): Array<[T, U, V]>; // tslint:disable-line:max-line-length
66+
2567
/**
2668
* Returns the n-fold Cartesian product.
2769
*
@@ -41,7 +83,7 @@ import { Collection } from '@stdlib/types/object';
4183
* var out = nCartesianProduct( x1, x2 );
4284
* // returns [ [ 1, 4 ], [ 1, 5 ], [ 2, 4 ], [ 2, 5 ], [ 3, 4 ], [ 3, 5 ] ]
4385
*/
44-
declare function nCartesianProduct( x1: Collection, x2: Collection, ...xN: Array<Collection> ): Array<Array<any>>; // tslint:disable-line:max-line-length
86+
declare function nCartesianProduct<T = any, U = any, V = any>( x1: Collection<T>, x2: Collection<U>, ...xN: Array<Collection<V>> ): Array<Array<T | U | V>>; // tslint:disable-line:max-line-length
4587

4688

4789
// EXPORTS //

lib/node_modules/@stdlib/array/base/n-cartesian-product/docs/types/test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import nCartesianProduct = require( './index' );
2323

2424
// The function returns an array of arrays...
2525
{
26-
nCartesianProduct( [ 1, 2, 3, 4 ], [ 1, 3 ] ); // $ExpectType any[][]
26+
nCartesianProduct( [ 1, 2, 3, 4 ], [ 1, 3 ] ); // $ExpectType [number, number][]
27+
nCartesianProduct( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 6 ] ); // $ExpectType [number, number, number][]
28+
nCartesianProduct( [ 1, 2, 3, 4 ], [ 1, 3 ], [ 6 ], [ 7 ] ); // $ExpectType number[][]
2729
}
2830

2931
// The compiler throws an error if the function is provided a first argument which is not an array-like object...

0 commit comments

Comments
 (0)