Skip to content

Commit d4710cd

Browse files
committed
fix: improve type specificity with overloads
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: skipped - task: lint_javascript_src status: na - 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 142964b commit d4710cd

File tree

2 files changed

+262
-19
lines changed
  • lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types

2 files changed

+262
-19
lines changed

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

Lines changed: 260 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19+
/* eslint-disable @typescript-eslint/prefer-function-type */
20+
1921
// TypeScript Version: 4.1
2022

2123
/// <reference types="@stdlib/types"/>
@@ -114,31 +116,47 @@ type NullaryWithFiveAdditionalArrays<T, U, V, W, X, Y> = ( arrays: [ typedndarra
114116
* @param options - function options
115117
* @returns result
116118
*/
117-
type NullaryWithAnyAdditionalArrays<T, U> = ( arrays: [ typedndarray<T>, ...Array<typedndarray<U>> ], options?: unknown ) => typedndarray<T>;
119+
type NullaryWithAdditionalArrays<T, U> = ( arrays: [ typedndarray<T>, ...Array<typedndarray<U>> ], options?: unknown ) => typedndarray<T>;
118120

119121
/**
120-
* Strided function.
121-
*
122-
* @param arrays - input ndarrays
123-
* @param options - function options
124-
* @returns result
122+
* Base dispatch table.
123+
*/
124+
interface BaseDispatchTable1<T> {
125+
/**
126+
* Default strided function.
127+
*/
128+
default: Nullary<T>;
129+
}
130+
131+
/**
132+
* Dispatch table.
125133
*/
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>;
134+
interface DispatchTable1<T> extends BaseDispatchTable1<T> {
135+
/**
136+
* One-dimensional list of ndarray data types describing specialized output ndarray argument signatures.
137+
*/
138+
types: ArrayLike<DataType>;
139+
140+
/**
141+
* List of strided functions which are specific to specialized output ndarray argument signatures.
142+
*/
143+
fcns: ArrayLike<Nullary<T>>;
144+
}
127145

128146
/**
129147
* Base dispatch table.
130148
*/
131-
interface BaseDispatchTable<T, U, V, W, X, Y> {
149+
interface BaseDispatchTable2<T, U> {
132150
/**
133151
* Default strided function.
134152
*/
135-
default: Nullary<T> | NullaryWithAdditionalArrays<T, U, V, W, X, Y>;
153+
default: NullaryWithOneAdditionalArray<T, U>;
136154
}
137155

138156
/**
139157
* Dispatch table.
140158
*/
141-
interface DispatchTable<T, U, V, W, X, Y> extends BaseDispatchTable<T, U, V, W, X, Y> {
159+
interface DispatchTable2<T, U> extends BaseDispatchTable2<T, U> {
142160
/**
143161
* One-dimensional list of ndarray data types describing specialized output ndarray argument signatures.
144162
*/
@@ -147,20 +165,159 @@ interface DispatchTable<T, U, V, W, X, Y> extends BaseDispatchTable<T, U, V, W,
147165
/**
148166
* List of strided functions which are specific to specialized output ndarray argument signatures.
149167
*/
150-
fcns: ArrayLike<Nullary<T> | NullaryWithAdditionalArrays<T, U, V, W, X, Y>>;
168+
fcns: ArrayLike<NullaryWithOneAdditionalArray<T, U>>;
151169
}
152170

171+
/**
172+
* Base dispatch table.
173+
*/
174+
interface BaseDispatchTable3<T, U, V> {
175+
/**
176+
* Default strided function.
177+
*/
178+
default: NullaryWithTwoAdditionalArrays<T, U, V>;
179+
}
180+
181+
/**
182+
* Dispatch table.
183+
*/
184+
interface DispatchTable3<T, U, V> extends BaseDispatchTable3<T, U, V> {
185+
/**
186+
* One-dimensional list of ndarray data types describing specialized output ndarray argument signatures.
187+
*/
188+
types: ArrayLike<DataType>;
189+
190+
/**
191+
* List of strided functions which are specific to specialized output ndarray argument signatures.
192+
*/
193+
fcns: ArrayLike<NullaryWithTwoAdditionalArrays<T, U, V>>;
194+
}
195+
196+
/**
197+
* Base dispatch table.
198+
*/
199+
interface BaseDispatchTable4<T, U, V, W> {
200+
/**
201+
* Default strided function.
202+
*/
203+
default: NullaryWithThreeAdditionalArrays<T, U, V, W>;
204+
}
205+
206+
/**
207+
* Dispatch table.
208+
*/
209+
interface DispatchTable4<T, U, V, W> extends BaseDispatchTable4<T, U, V, W> {
210+
/**
211+
* One-dimensional list of ndarray data types describing specialized output ndarray argument signatures.
212+
*/
213+
types: ArrayLike<DataType>;
214+
215+
/**
216+
* List of strided functions which are specific to specialized output ndarray argument signatures.
217+
*/
218+
fcns: ArrayLike<NullaryWithThreeAdditionalArrays<T, U, V, W>>;
219+
}
220+
221+
/**
222+
* Base dispatch table.
223+
*/
224+
interface BaseDispatchTable5<T, U, V, W, X> {
225+
/**
226+
* Default strided function.
227+
*/
228+
default: NullaryWithFourAdditionalArrays<T, U, V, W, X>;
229+
}
230+
231+
/**
232+
* Dispatch table.
233+
*/
234+
interface DispatchTable5<T, U, V, W, X> extends BaseDispatchTable5<T, U, V, W, X> {
235+
/**
236+
* One-dimensional list of ndarray data types describing specialized output ndarray argument signatures.
237+
*/
238+
types: ArrayLike<DataType>;
239+
240+
/**
241+
* List of strided functions which are specific to specialized output ndarray argument signatures.
242+
*/
243+
fcns: ArrayLike<NullaryWithFourAdditionalArrays<T, U, V, W, X>>;
244+
}
245+
246+
/**
247+
* Base dispatch table.
248+
*/
249+
interface BaseDispatchTable6<T, U, V, W, X, Y> {
250+
/**
251+
* Default strided function.
252+
*/
253+
default: NullaryWithFiveAdditionalArrays<T, U, V, W, X, Y>;
254+
}
255+
256+
/**
257+
* Dispatch table.
258+
*/
259+
interface DispatchTable6<T, U, V, W, X, Y> extends BaseDispatchTable6<T, U, V, W, X, Y> {
260+
/**
261+
* One-dimensional list of ndarray data types describing specialized output ndarray argument signatures.
262+
*/
263+
types: ArrayLike<DataType>;
264+
265+
/**
266+
* List of strided functions which are specific to specialized output ndarray argument signatures.
267+
*/
268+
fcns: ArrayLike<NullaryWithFiveAdditionalArrays<T, U, V, W, X, Y>>;
269+
}
270+
271+
/**
272+
* Base dispatch table.
273+
*/
274+
interface BaseDispatchTable<T, U> {
275+
/**
276+
* Default strided function.
277+
*/
278+
default: Nullary<T> | NullaryWithAdditionalArrays<T, U>;
279+
}
280+
281+
/**
282+
* Dispatch table.
283+
*/
284+
interface DispatchTable<T, U> extends BaseDispatchTable<T, U> {
285+
/**
286+
* One-dimensional list of ndarray data types describing specialized output ndarray argument signatures.
287+
*/
288+
types: ArrayLike<DataType>;
289+
290+
/**
291+
* List of strided functions which are specific to specialized output ndarray argument signatures.
292+
*/
293+
fcns: ArrayLike<Nullary<T> | NullaryWithAdditionalArrays<T, U>>;
294+
}
153295

154296
/**
155297
* Interface for applying an operation to an ndarray.
156298
*/
157-
interface NullaryFunction<T, U, Z> {
299+
interface NullaryFunction1<T> {
158300
/**
159301
* Applies a strided function and assign results to a provided output ndarray.
160302
*
161303
* @param out - output ndarray
162304
* @param options - function options
163305
* @returns output ndarray
306+
*/
307+
<Out extends OutputArray<T> = OutputArray<T>>( out: Out, options?: BaseOptions ): Out;
308+
}
309+
310+
/**
311+
* Interface for applying an operation to an ndarray.
312+
*/
313+
interface NullaryFunction2<T, U> {
314+
/**
315+
* Applies a strided function and assigns results to a provided output ndarray.
316+
*
317+
* @param out - output ndarray
318+
* @param x1 - first additional ndarray argument
319+
* @param options - function options
320+
* @returns output ndarray
164321
*
165322
* @example
166323
* var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' );
@@ -180,7 +337,7 @@ interface NullaryFunction<T, U, Z> {
180337
* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
181338
*
182339
* var order = scalar2ndarray( 1.0, {
183-
* 'dtype': 'generic'
340+
* 'dtype': 'generic'
184341
* });
185342
*
186343
* var out = sorthp( x, order );
@@ -189,13 +346,87 @@ interface NullaryFunction<T, U, Z> {
189346
* var bool = ( out === x );
190347
* // returns true
191348
*/
192-
<Out extends OutputArray<T> = OutputArray<T>>( out: Out, options?: BaseOptions ): Out;
349+
<Out extends OutputArray<T> = OutputArray<T>, X1 extends InputArray<U> = InputArray<U>>( out: Out, x1: X1, options?: BaseOptions ): Out;
350+
}
351+
352+
/**
353+
* Interface for applying an operation to an ndarray.
354+
*/
355+
interface NullaryFunction3<T, U, V> {
356+
/**
357+
* Applies a strided function and assigns results to a provided output ndarray.
358+
*
359+
* @param out - output ndarray
360+
* @param x1 - first additional ndarray argument
361+
* @param x2 - second additional ndarray argument
362+
* @param options - function options
363+
* @returns output ndarray
364+
*/
365+
<Out extends OutputArray<T> = OutputArray<T>, X1 extends InputArray<U> = InputArray<U>, X2 extends InputArray<V> = InputArray<V>>( out: Out, x1: X1, x2: X2, options?: BaseOptions ): Out;
366+
}
367+
368+
/**
369+
* Interface for applying an operation to an ndarray.
370+
*/
371+
interface NullaryFunction4<T, U, V, W> {
372+
/**
373+
* Applies a strided function and assigns results to a provided output ndarray.
374+
*
375+
* @param out - output ndarray
376+
* @param x1 - first additional ndarray argument
377+
* @param x2 - second additional ndarray argument
378+
* @param x3 - third additional ndarray argument
379+
* @param options - function options
380+
* @returns output ndarray
381+
*/
382+
<Out extends OutputArray<T> = OutputArray<T>, X1 extends InputArray<U> = InputArray<U>, X2 extends InputArray<V> = InputArray<V>, X3 extends InputArray<W> = InputArray<W>>( out: Out, x1: X1, x2: X2, x3: X3, options?: BaseOptions ): Out;
383+
}
384+
385+
/**
386+
* Interface for applying an operation to an ndarray.
387+
*/
388+
interface NullaryFunction5<T, U, V, W, X> {
389+
/**
390+
* Applies a strided function and assigns results to a provided output ndarray.
391+
*
392+
* @param out - output ndarray
393+
* @param x1 - first additional ndarray argument
394+
* @param x2 - second additional ndarray argument
395+
* @param x3 - third additional ndarray argument
396+
* @param x4 - fourth additional ndarray argument
397+
* @param options - function options
398+
* @returns output ndarray
399+
*/
400+
<Out extends OutputArray<T> = OutputArray<T>, X1 extends InputArray<U> = InputArray<U>, X2 extends InputArray<V> = InputArray<V>, X3 extends InputArray<W> = InputArray<W>, X4 extends InputArray<X> = InputArray<X>>( out: Out, x1: X1, x2: X2, x3: X3, x4: X4, options?: BaseOptions ): Out;
401+
}
193402

403+
/**
404+
* Interface for applying an operation to an ndarray.
405+
*/
406+
interface NullaryFunction6<T, U, V, W, X, Y> {
407+
/**
408+
* Applies a strided function and assigns results to a provided output ndarray.
409+
*
410+
* @param out - output ndarray
411+
* @param x1 - first additional ndarray argument
412+
* @param x2 - second additional ndarray argument
413+
* @param x3 - third additional ndarray argument
414+
* @param x4 - fourth additional ndarray argument
415+
* @param x5 - fifth additional ndarray argument
416+
* @param options - function options
417+
* @returns output ndarray
418+
*/
419+
<Out extends OutputArray<T> = OutputArray<T>, X1 extends InputArray<U> = InputArray<U>, X2 extends InputArray<V> = InputArray<V>, X3 extends InputArray<W> = InputArray<W>, X4 extends InputArray<X> = InputArray<X>, X5 extends InputArray<Y> = InputArray<Y>>( out: Out, x1: X1, x2: X2, x3: X3, x4: X4, x5: X5, options?: BaseOptions ): Out;
420+
}
421+
422+
/**
423+
* Interface for applying an operation to an ndarray.
424+
*/
425+
interface NullaryFunction<T, Z> {
194426
/**
195427
* Applies a strided function and assigns results to a provided output ndarray.
196428
*
197429
* @param out - output ndarray
198-
* @param x - additional ndarray argument
199430
* @param args - output ndarray, additional array arguments, and function options
200431
* @returns output ndarray
201432
*
@@ -226,7 +457,7 @@ interface NullaryFunction<T, U, Z> {
226457
* var bool = ( out === x );
227458
* // returns true
228459
*/
229-
<Out extends OutputArray<T> = OutputArray<T>>( out: Out, x: InputArray<U>, ...args: Array<InputArray<Z> | BaseOptions> ): Out;
460+
<Out extends OutputArray<T> = OutputArray<T>>( out: Out, ...args: Array<InputArray<Z> | BaseOptions> ): Out;
230461
}
231462

232463
/**
@@ -265,7 +496,19 @@ interface NullaryFunction<T, U, Z> {
265496
* var bool = ( out === x );
266497
* // returns true
267498
*/
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>;
499+
declare function factory<T = unknown>( table: DispatchTable1<T> | BaseDispatchTable1<T>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, options?: FactoryOptions ): NullaryFunction1<T>;
500+
501+
declare function factory<T = unknown, U = unknown>( table: DispatchTable2<T, U> | BaseDispatchTable2<T, U>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, options?: FactoryOptions ): NullaryFunction2<T, U>;
502+
503+
declare function factory<T = unknown, U = unknown, V = unknown>( table: DispatchTable3<T, U, V> | BaseDispatchTable3<T, U, V>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, options?: FactoryOptions ): NullaryFunction3<T, U, V>;
504+
505+
declare function factory<T = unknown, U = unknown, V = unknown, W = unknown>( table: DispatchTable4<T, U, V, W> | BaseDispatchTable4<T, U, V, W>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, options?: FactoryOptions ): NullaryFunction4<T, U, V, W>;
506+
507+
declare function factory<T = unknown, U = unknown, V = unknown, W = unknown, X = unknown>( table: DispatchTable5<T, U, V, W, X> | BaseDispatchTable5<T, U, V, W, X>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, options?: FactoryOptions ): NullaryFunction5<T, U, V, W, X>;
508+
509+
declare function factory<T = unknown, U = unknown, V = unknown, W = unknown, X = unknown, Y = unknown>( table: DispatchTable6<T, U, V, W, X, Y> | BaseDispatchTable6<T, U, V, W, X, Y>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, options?: FactoryOptions ): NullaryFunction6<T, U, V, W, X, Y>;
510+
511+
declare function factory<T = unknown, U = unknown>( table: DispatchTable<T, U> | BaseDispatchTable<T, U>, idtypes: ArrayLike<ArrayLike<DataType>>, odtypes: ArrayLike<DataType>, options?: FactoryOptions ): NullaryFunction<T, U>;
269512

270513

271514
// EXPORTS //

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

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

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

4343
// The compiler throws an error if the function is provided a first argument which is not a dispatch table...

0 commit comments

Comments
 (0)