Skip to content

Commit 142964b

Browse files
committed
feat!: refactor declarations to satisfy TS's structural typing
BREAKING CHANGE: add additional type parameters To migrate, users should update their signatures according to the types of the additional array arguments provided to the strided function. For fixed arity strided function wrappers, the previous declarations would choke, as they expected such wrappers to be variadic in the number of accepted arrays. This commit rectifies that by enumerating various fixed array arity signatures. --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: skipped - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent f52054e commit 142964b

File tree

6 files changed

+129
-99
lines changed

6 files changed

+129
-99
lines changed

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ Applies a strided function and assigns results to a provided output ndarray.
8181
var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' );
8282
var dtypes = require( '@stdlib/ndarray/dtypes' );
8383
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
84-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
8584
var ndarray = require( '@stdlib/ndarray/base/ctor' );
8685

8786
var idt = dtypes( 'real_and_generic' );
@@ -100,10 +99,7 @@ var order = scalar2ndarray( 1.0, {
10099
});
101100

102101
var out = nullary( x, order );
103-
// returns <ndarray>
104-
105-
var arr = ndarray2array( out );
106-
// returns [ -3.0, -1.0, 2.0 ]
102+
// returns <ndarray>[ -3.0, -1.0, 2.0 ]
107103

108104
var bool = ( out === x );
109105
// returns true

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/repl.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
- arrays: array containing an output ndarray, followed by any additional
2929
ndarray arguments.
3030

31-
idtypes: Array<Array<string>>
31+
idtypes: Array<Array<string|DataType>>
3232
List containing lists of supported input data types for each input
3333
ndarray argument.
3434

35-
odtypes: Array<string>
35+
odtypes: Array<string|DataType>
3636
List of supported output data types.
3737

3838
options: Object (optional)

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/index.d.ts

Lines changed: 67 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type InputArray<T> = typedndarray<T>;
3131
/**
3232
* Output array.
3333
*/
34-
type OutputArray<U> = typedndarray<U>;
34+
type OutputArray<T> = typedndarray<T>;
3535

3636
/**
3737
* Interface defining "base" options.
@@ -69,22 +69,76 @@ type Nullary<T> = ( arrays: [ typedndarray<T> ], options?: unknown ) => typednda
6969
* @param options - function options
7070
* @returns result
7171
*/
72-
type NullaryWithAdditionalArrays<T> = ( arrays: [ typedndarray<T>, ...Array<typedndarray<T>> ], options?: unknown ) => typedndarray<T>;
72+
type NullaryWithOneAdditionalArray<T, U> = ( arrays: [ typedndarray<T>, typedndarray<U> ], options?: unknown ) => typedndarray<T>;
73+
74+
/**
75+
* Strided function.
76+
*
77+
* @param arrays - input ndarrays
78+
* @param options - function options
79+
* @returns result
80+
*/
81+
type NullaryWithTwoAdditionalArrays<T, U, V> = ( arrays: [ typedndarray<T>, typedndarray<U>, typedndarray<V> ], options?: unknown ) => typedndarray<T>;
82+
83+
/**
84+
* Strided function.
85+
*
86+
* @param arrays - input ndarrays
87+
* @param options - function options
88+
* @returns result
89+
*/
90+
type NullaryWithThreeAdditionalArrays<T, U, V, W> = ( arrays: [ typedndarray<T>, typedndarray<U>, typedndarray<V>, typedndarray<W> ], options?: unknown ) => typedndarray<T>;
91+
92+
/**
93+
* Strided function.
94+
*
95+
* @param arrays - input ndarrays
96+
* @param options - function options
97+
* @returns result
98+
*/
99+
type NullaryWithFourAdditionalArrays<T, U, V, W, X> = ( arrays: [ typedndarray<T>, typedndarray<U>, typedndarray<V>, typedndarray<W>, typedndarray<X> ], options?: unknown ) => typedndarray<T>;
100+
101+
/**
102+
* Strided function.
103+
*
104+
* @param arrays - input ndarrays
105+
* @param options - function options
106+
* @returns result
107+
*/
108+
type NullaryWithFiveAdditionalArrays<T, U, V, W, X, Y> = ( arrays: [ typedndarray<T>, typedndarray<U>, typedndarray<V>, typedndarray<W>, typedndarray<X>, typedndarray<Y> ], options?: unknown ) => typedndarray<T>;
109+
110+
/**
111+
* Strided function.
112+
*
113+
* @param arrays - input ndarrays
114+
* @param options - function options
115+
* @returns result
116+
*/
117+
type NullaryWithAnyAdditionalArrays<T, U> = ( arrays: [ typedndarray<T>, ...Array<typedndarray<U>> ], options?: unknown ) => typedndarray<T>;
118+
119+
/**
120+
* Strided function.
121+
*
122+
* @param arrays - input ndarrays
123+
* @param options - function options
124+
* @returns result
125+
*/
126+
type NullaryWithAdditionalArrays<T, U, V, W, X, Y> = NullaryWithOneAdditionalArray<T, U> | NullaryWithTwoAdditionalArrays<T, U, V> | NullaryWithThreeAdditionalArrays<T, U, V, W> | NullaryWithFourAdditionalArrays<T, U, V, W, X> | NullaryWithFiveAdditionalArrays<T, U, V, W, X, Y> | NullaryWithAnyAdditionalArrays<T, U>;
73127

74128
/**
75129
* Base dispatch table.
76130
*/
77-
interface BaseDispatchTable<T> {
131+
interface BaseDispatchTable<T, U, V, W, X, Y> {
78132
/**
79133
* Default strided function.
80134
*/
81-
default: Nullary<T> | NullaryWithAdditionalArrays<T>;
135+
default: Nullary<T> | NullaryWithAdditionalArrays<T, U, V, W, X, Y>;
82136
}
83137

84138
/**
85139
* Dispatch table.
86140
*/
87-
interface DispatchTable<T> extends BaseDispatchTable<T> {
141+
interface DispatchTable<T, U, V, W, X, Y> extends BaseDispatchTable<T, U, V, W, X, Y> {
88142
/**
89143
* One-dimensional list of ndarray data types describing specialized output ndarray argument signatures.
90144
*/
@@ -93,14 +147,14 @@ interface DispatchTable<T> extends BaseDispatchTable<T> {
93147
/**
94148
* List of strided functions which are specific to specialized output ndarray argument signatures.
95149
*/
96-
fcns: ArrayLike<Nullary<T> | NullaryWithAdditionalArrays<T>>;
150+
fcns: ArrayLike<Nullary<T> | NullaryWithAdditionalArrays<T, U, V, W, X, Y>>;
97151
}
98152

99153

100154
/**
101155
* Interface for applying an operation to an ndarray.
102156
*/
103-
interface NullaryFunction<T> {
157+
interface NullaryFunction<T, U, Z> {
104158
/**
105159
* Applies a strided function and assign results to a provided output ndarray.
106160
*
@@ -112,7 +166,6 @@ interface NullaryFunction<T> {
112166
* var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' );
113167
* var dtypes = require( '@stdlib/ndarray/dtypes' );
114168
* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
115-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
116169
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
117170
*
118171
* var idt = dtypes( 'real_and_generic' );
@@ -131,15 +184,12 @@ interface NullaryFunction<T> {
131184
* });
132185
*
133186
* var out = sorthp( x, order );
134-
* // returns <ndarray>
135-
*
136-
* var arr = ndarray2array( out );
137-
* // returns [ -3.0, -1.0, 2.0 ]
187+
* // returns <ndarray>[ -3.0, -1.0, 2.0 ]
138188
*
139189
* var bool = ( out === x );
140190
* // returns true
141191
*/
142-
<V extends OutputArray<T> = OutputArray<T>>( out: V, options?: BaseOptions ): V;
192+
<Out extends OutputArray<T> = OutputArray<T>>( out: Out, options?: BaseOptions ): Out;
143193

144194
/**
145195
* Applies a strided function and assigns results to a provided output ndarray.
@@ -153,7 +203,6 @@ interface NullaryFunction<T> {
153203
* var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' );
154204
* var dtypes = require( '@stdlib/ndarray/dtypes' );
155205
* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
156-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
157206
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
158207
*
159208
* var idt = dtypes( 'real_and_generic' );
@@ -172,15 +221,12 @@ interface NullaryFunction<T> {
172221
* });
173222
*
174223
* var out = sorthp( x, order );
175-
* // returns <ndarray>
176-
*
177-
* var arr = ndarray2array( out );
178-
* // returns [ -3.0, -1.0, 2.0 ]
224+
* // returns <ndarray>[ -3.0, -1.0, 2.0 ]
179225
*
180226
* var bool = ( out === x );
181227
* // returns true
182228
*/
183-
<V extends OutputArray<T> = OutputArray<T>>( out: V, x: InputArray<T>, ...args: Array<V | BaseOptions> ): V;
229+
<Out extends OutputArray<T> = OutputArray<T>>( out: Out, x: InputArray<U>, ...args: Array<InputArray<Z> | BaseOptions> ): Out;
184230
}
185231

186232
/**
@@ -196,7 +242,6 @@ interface NullaryFunction<T> {
196242
* var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' );
197243
* var dtypes = require( '@stdlib/ndarray/dtypes' );
198244
* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
199-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
200245
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
201246
*
202247
* var idt = dtypes( 'real_and_generic' );
@@ -215,15 +260,12 @@ interface NullaryFunction<T> {
215260
* });
216261
*
217262
* var out = sorthp( x, order );
218-
* // returns <ndarray>
219-
*
220-
* var arr = ndarray2array( out );
221-
* // returns [ -3.0, -1.0, 2.0 ]
263+
* // returns <ndarray>[ -3.0, -1.0, 2.0 ]
222264
*
223265
* var bool = ( out === x );
224266
* // returns true
225267
*/
226-
declare function factory<T = unknown>( table: DispatchTable<T> | BaseDispatchTable<T>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, options?: FactoryOptions ): NullaryFunction<T>;
268+
declare function factory<T = unknown, U = unknown, V = unknown, W = unknown, X = unknown, Y = unknown>( table: DispatchTable<T, U, V, W, X, Y> | BaseDispatchTable<T, U, V, W, X, Y>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, options?: FactoryOptions ): NullaryFunction<T, U, V | W | X | Y>;
227269

228270

229271
// EXPORTS //

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/test.ts

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ import factory = require( './index' );
3636
'default': gsorthp
3737
};
3838

39-
factory<number>( table, [ dtypes ], dtypes ); // $ExpectType NullaryFunction<number>
40-
factory<number>( table, [ dtypes ], dtypes, {} ); // $ExpectType NullaryFunction<number>
39+
factory<unknown, number>( table, [ dtypes ], dtypes ); // $ExpectType NullaryFunction<unknown, number, unknown>
40+
factory<unknown, number>( table, [ dtypes ], dtypes, {} ); // $ExpectType NullaryFunction<unknown, number, unknown>
4141
}
4242

4343
// The compiler throws an error if the function is provided a first argument which is not a dispatch table...
@@ -72,25 +72,25 @@ import factory = require( './index' );
7272
'default': gsorthp
7373
};
7474

75-
factory<number>( table, '5', dtypes ); // $ExpectError
76-
factory<number>( table, 5, dtypes ); // $ExpectError
77-
factory<number>( table, true, dtypes ); // $ExpectError
78-
factory<number>( table, false, dtypes ); // $ExpectError
79-
factory<number>( table, null, dtypes ); // $ExpectError
80-
factory<number>( table, void 0, dtypes ); // $ExpectError
81-
factory<number>( table, 'abc', dtypes ); // $ExpectError
82-
factory<number>( table, {}, dtypes ); // $ExpectError
83-
factory<number>( table, ( x: number ): number => x, dtypes ); // $ExpectError
84-
85-
factory<number>( table, '5', dtypes, {} ); // $ExpectError
86-
factory<number>( table, 5, dtypes, {} ); // $ExpectError
87-
factory<number>( table, true, dtypes, {} ); // $ExpectError
88-
factory<number>( table, false, dtypes, {} ); // $ExpectError
89-
factory<number>( table, null, dtypes, {} ); // $ExpectError
90-
factory<number>( table, void 0, dtypes, {} ); // $ExpectError
91-
factory<number>( table, 'abc', dtypes, {} ); // $ExpectError
92-
factory<number>( table, {}, dtypes, {} ); // $ExpectError
93-
factory<number>( table, ( x: number ): number => x, dtypes, {} ); // $ExpectError
75+
factory<unknown, number>( table, '5', dtypes ); // $ExpectError
76+
factory<unknown, number>( table, 5, dtypes ); // $ExpectError
77+
factory<unknown, number>( table, true, dtypes ); // $ExpectError
78+
factory<unknown, number>( table, false, dtypes ); // $ExpectError
79+
factory<unknown, number>( table, null, dtypes ); // $ExpectError
80+
factory<unknown, number>( table, void 0, dtypes ); // $ExpectError
81+
factory<unknown, number>( table, 'abc', dtypes ); // $ExpectError
82+
factory<unknown, number>( table, {}, dtypes ); // $ExpectError
83+
factory<unknown, number>( table, ( x: number ): number => x, dtypes ); // $ExpectError
84+
85+
factory<unknown, number>( table, '5', dtypes, {} ); // $ExpectError
86+
factory<unknown, number>( table, 5, dtypes, {} ); // $ExpectError
87+
factory<unknown, number>( table, true, dtypes, {} ); // $ExpectError
88+
factory<unknown, number>( table, false, dtypes, {} ); // $ExpectError
89+
factory<unknown, number>( table, null, dtypes, {} ); // $ExpectError
90+
factory<unknown, number>( table, void 0, dtypes, {} ); // $ExpectError
91+
factory<unknown, number>( table, 'abc', dtypes, {} ); // $ExpectError
92+
factory<unknown, number>( table, {}, dtypes, {} ); // $ExpectError
93+
factory<unknown, number>( table, ( x: number ): number => x, dtypes, {} ); // $ExpectError
9494
}
9595

9696
// The compiler throws an error if the function is provided a third argument which is not a list of data types...
@@ -100,25 +100,25 @@ import factory = require( './index' );
100100
'default': gsorthp
101101
};
102102

103-
factory<number>( table, [ dtypes ], '5' ); // $ExpectError
104-
factory<number>( table, [ dtypes ], 5 ); // $ExpectError
105-
factory<number>( table, [ dtypes ], true ); // $ExpectError
106-
factory<number>( table, [ dtypes ], false ); // $ExpectError
107-
factory<number>( table, [ dtypes ], null ); // $ExpectError
108-
factory<number>( table, [ dtypes ], void 0 ); // $ExpectError
109-
factory<number>( table, [ dtypes ], 'abc' ); // $ExpectError
110-
factory<number>( table, [ dtypes ], {} ); // $ExpectError
111-
factory<number>( table, [ dtypes ], ( x: number ): number => x ); // $ExpectError
112-
113-
factory<number>( table, [ dtypes ], '5', {} ); // $ExpectError
114-
factory<number>( table, [ dtypes ], 5, {} ); // $ExpectError
115-
factory<number>( table, [ dtypes ], true, {} ); // $ExpectError
116-
factory<number>( table, [ dtypes ], false, {} ); // $ExpectError
117-
factory<number>( table, [ dtypes ], null, {} ); // $ExpectError
118-
factory<number>( table, [ dtypes ], void 0, {} ); // $ExpectError
119-
factory<number>( table, [ dtypes ], 'abc', {} ); // $ExpectError
120-
factory<number>( table, [ dtypes ], {}, {} ); // $ExpectError
121-
factory<number>( table, [ dtypes ], ( x: number ): number => x, {} ); // $ExpectError
103+
factory<unknown, number>( table, [ dtypes ], '5' ); // $ExpectError
104+
factory<unknown, number>( table, [ dtypes ], 5 ); // $ExpectError
105+
factory<unknown, number>( table, [ dtypes ], true ); // $ExpectError
106+
factory<unknown, number>( table, [ dtypes ], false ); // $ExpectError
107+
factory<unknown, number>( table, [ dtypes ], null ); // $ExpectError
108+
factory<unknown, number>( table, [ dtypes ], void 0 ); // $ExpectError
109+
factory<unknown, number>( table, [ dtypes ], 'abc' ); // $ExpectError
110+
factory<unknown, number>( table, [ dtypes ], {} ); // $ExpectError
111+
factory<unknown, number>( table, [ dtypes ], ( x: number ): number => x ); // $ExpectError
112+
113+
factory<unknown, number>( table, [ dtypes ], '5', {} ); // $ExpectError
114+
factory<unknown, number>( table, [ dtypes ], 5, {} ); // $ExpectError
115+
factory<unknown, number>( table, [ dtypes ], true, {} ); // $ExpectError
116+
factory<unknown, number>( table, [ dtypes ], false, {} ); // $ExpectError
117+
factory<unknown, number>( table, [ dtypes ], null, {} ); // $ExpectError
118+
factory<unknown, number>( table, [ dtypes ], void 0, {} ); // $ExpectError
119+
factory<unknown, number>( table, [ dtypes ], 'abc', {} ); // $ExpectError
120+
factory<unknown, number>( table, [ dtypes ], {}, {} ); // $ExpectError
121+
factory<unknown, number>( table, [ dtypes ], ( x: number ): number => x, {} ); // $ExpectError
122122
}
123123

124124
// The compiler throws an error if the function is provided a fourth argument which is not an object...
@@ -128,13 +128,13 @@ import factory = require( './index' );
128128
'default': gsorthp
129129
};
130130

131-
factory<number>( table, [ dtypes ], dtypes, '5' ); // $ExpectError
132-
factory<number>( table, [ dtypes ], dtypes, 5 ); // $ExpectError
133-
factory<number>( table, [ dtypes ], dtypes, true ); // $ExpectError
134-
factory<number>( table, [ dtypes ], dtypes, false ); // $ExpectError
135-
factory<number>( table, [ dtypes ], dtypes, null ); // $ExpectError
136-
factory<number>( table, [ dtypes ], dtypes, 'abc' ); // $ExpectError
137-
factory<number>( table, [ dtypes ], dtypes, ( x: number ): number => x ); // $ExpectError
131+
factory<unknown, number>( table, [ dtypes ], dtypes, '5' ); // $ExpectError
132+
factory<unknown, number>( table, [ dtypes ], dtypes, 5 ); // $ExpectError
133+
factory<unknown, number>( table, [ dtypes ], dtypes, true ); // $ExpectError
134+
factory<unknown, number>( table, [ dtypes ], dtypes, false ); // $ExpectError
135+
factory<unknown, number>( table, [ dtypes ], dtypes, null ); // $ExpectError
136+
factory<unknown, number>( table, [ dtypes ], dtypes, 'abc' ); // $ExpectError
137+
factory<unknown, number>( table, [ dtypes ], dtypes, ( x: number ): number => x ); // $ExpectError
138138
}
139139

140140
// The compiler throws an error if the function is provided an unsupported number of arguments...
@@ -145,9 +145,9 @@ import factory = require( './index' );
145145
};
146146

147147
factory(); // $ExpectError
148-
factory<number>( table ); // $ExpectError
149-
factory<number>( table, [ dtypes ] ); // $ExpectError
150-
factory<number>( table, [ dtypes ], dtypes, {}, {} ); // $ExpectError
148+
factory<unknown, number>( table ); // $ExpectError
149+
factory<unknown, number>( table, [ dtypes ] ); // $ExpectError
150+
factory<unknown, number>( table, [ dtypes ], dtypes, {}, {} ); // $ExpectError
151151
}
152152

153153
// The function returns a function which returns an ndarray...
@@ -163,7 +163,7 @@ import factory = require( './index' );
163163
'dtype': 'generic'
164164
});
165165

166-
const f = factory<number>( table, [ dtypes ], dtypes );
166+
const f = factory<unknown, number>( table, [ dtypes ], dtypes );
167167
f( x ); // $ExpectType float64ndarray
168168
f( x, o ); // $ExpectType float64ndarray
169169
}
@@ -175,7 +175,7 @@ import factory = require( './index' );
175175
'default': gsorthp
176176
};
177177

178-
const f = factory<number>( table, [ dtypes ], dtypes );
178+
const f = factory<unknown, number>( table, [ dtypes ], dtypes );
179179
f( '5' ); // $ExpectError
180180
f( 5 ); // $ExpectError
181181
f( true ); // $ExpectError
@@ -208,7 +208,7 @@ import factory = require( './index' );
208208
'dtype': 'generic'
209209
});
210210

211-
const f = factory<number>( table, [ dtypes ], dtypes );
211+
const f = factory<unknown, number>( table, [ dtypes ], dtypes );
212212
f( x, { 'dims': '5' } ); // $ExpectError
213213
f( x, { 'dims': 5 } ); // $ExpectError
214214
f( x, { 'dims': true } ); // $ExpectError
@@ -233,6 +233,6 @@ import factory = require( './index' );
233233
'default': gsorthp
234234
};
235235

236-
const f = factory<number>( table, [ dtypes ], dtypes );
236+
const f = factory<unknown, number>( table, [ dtypes ], dtypes );
237237
f(); // $ExpectError
238238
}

0 commit comments

Comments
 (0)