From 5ac4541ccbf3d284edbc0b3ebe67f5718631d805 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 31 May 2026 01:12:15 -0500 Subject: [PATCH] fix: type map2d/map3d/map4d/map5d callback indices as an array The `Binary` and `Ternary` callback types declared the third argument as `index: number`, but the implementations invoke the callback with an array of dimension indices (e.g. `[ i, j ]` for `map2d`, `[ i, j, k ]` for `map3d`, etc.), and the accompanying TSDoc already documents the argument as `indices`. Retype the argument as `indices: Array` in the `Binary` and `Ternary` callback signatures of `map2d`, `map3d`, `map4d`, and `map5d`, and add declaration tests exercising a callback that consumes the indices array. --- 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_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - 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 --- --- .../@stdlib/utils/map2d/docs/types/index.d.ts | 4 ++-- .../@stdlib/utils/map2d/docs/types/test.ts | 12 ++++++++++++ .../@stdlib/utils/map3d/docs/types/index.d.ts | 4 ++-- .../@stdlib/utils/map3d/docs/types/test.ts | 12 ++++++++++++ .../@stdlib/utils/map4d/docs/types/index.d.ts | 4 ++-- .../@stdlib/utils/map4d/docs/types/test.ts | 12 ++++++++++++ .../@stdlib/utils/map5d/docs/types/index.d.ts | 4 ++-- .../@stdlib/utils/map5d/docs/types/test.ts | 12 ++++++++++++ 8 files changed, 56 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/map2d/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/map2d/docs/types/index.d.ts index e6082b953583..106e13eb87e4 100644 --- a/lib/node_modules/@stdlib/utils/map2d/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/map2d/docs/types/index.d.ts @@ -49,7 +49,7 @@ type Unary = ( this: V, value: T ) => U; * @param indices - current array element indices * @returns result */ -type Binary = ( this: V, value: T, index: number ) => U; +type Binary = ( this: V, value: T, indices: Array ) => U; /** * Callback invoked for each array element. @@ -59,7 +59,7 @@ type Binary = ( this: V, value: T, index: number ) => U; * @param arr - array * @returns result */ -type Ternary = ( this: V, value: T, index: number, arr: Array2D ) => U; +type Ternary = ( this: V, value: T, indices: Array, arr: Array2D ) => U; /** * Callback invoked for each array element. diff --git a/lib/node_modules/@stdlib/utils/map2d/docs/types/test.ts b/lib/node_modules/@stdlib/utils/map2d/docs/types/test.ts index 56da641c3256..fcacb977a9a6 100644 --- a/lib/node_modules/@stdlib/utils/map2d/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/map2d/docs/types/test.ts @@ -28,6 +28,17 @@ function clbk( v: number ): number { return v; } +/** +* Callback function. +* +* @param v - argument +* @param indices - element indices +* @returns result +*/ +function clbki( v: number, indices: Array ): number { + return v + indices[ 0 ]; +} + // TESTS // @@ -40,6 +51,7 @@ function clbk( v: number ): number { map2d( arr, clbk ); // $ExpectType number[][] map2d( arr, clbk, {} ); // $ExpectType number[][] + map2d( arr, clbki ); // $ExpectType number[][] } // The compiler throws an error if the function is provided a first argument other than an array of arrays... diff --git a/lib/node_modules/@stdlib/utils/map3d/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/map3d/docs/types/index.d.ts index e80208b624b5..ee78a7b1d92a 100644 --- a/lib/node_modules/@stdlib/utils/map3d/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/map3d/docs/types/index.d.ts @@ -49,7 +49,7 @@ type Unary = ( this: V, value: T ) => U; * @param indices - current array element indices * @returns result */ -type Binary = ( this: V, value: T, index: number ) => U; +type Binary = ( this: V, value: T, indices: Array ) => U; /** * Callback invoked for each array element. @@ -59,7 +59,7 @@ type Binary = ( this: V, value: T, index: number ) => U; * @param arr - array * @returns result */ -type Ternary = ( this: V, value: T, index: number, arr: Array3D ) => U; +type Ternary = ( this: V, value: T, indices: Array, arr: Array3D ) => U; /** * Callback invoked for each array element. diff --git a/lib/node_modules/@stdlib/utils/map3d/docs/types/test.ts b/lib/node_modules/@stdlib/utils/map3d/docs/types/test.ts index 6491d207eb58..73873b588a5c 100644 --- a/lib/node_modules/@stdlib/utils/map3d/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/map3d/docs/types/test.ts @@ -28,6 +28,17 @@ function clbk( v: number ): number { return v; } +/** +* Callback function. +* +* @param v - argument +* @param indices - element indices +* @returns result +*/ +function clbki( v: number, indices: Array ): number { + return v + indices[ 0 ]; +} + // TESTS // @@ -40,6 +51,7 @@ function clbk( v: number ): number { map3d( arr, clbk ); // $ExpectType number[][][] map3d( arr, clbk, {} ); // $ExpectType number[][][] + map3d( arr, clbki ); // $ExpectType number[][][] } // The compiler throws an error if the function is provided a first argument other than a three-dimensional nested array... diff --git a/lib/node_modules/@stdlib/utils/map4d/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/map4d/docs/types/index.d.ts index 6242bf689522..7d3db2824a53 100644 --- a/lib/node_modules/@stdlib/utils/map4d/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/map4d/docs/types/index.d.ts @@ -49,7 +49,7 @@ type Unary = ( this: V, value: T ) => U; * @param indices - current array element indices * @returns result */ -type Binary = ( this: V, value: T, index: number ) => U; +type Binary = ( this: V, value: T, indices: Array ) => U; /** * Callback invoked for each array element. @@ -59,7 +59,7 @@ type Binary = ( this: V, value: T, index: number ) => U; * @param arr - array * @returns result */ -type Ternary = ( this: V, value: T, index: number, arr: Array4D ) => U; +type Ternary = ( this: V, value: T, indices: Array, arr: Array4D ) => U; /** * Callback invoked for each array element. diff --git a/lib/node_modules/@stdlib/utils/map4d/docs/types/test.ts b/lib/node_modules/@stdlib/utils/map4d/docs/types/test.ts index fa886d790583..737b85ce07bb 100644 --- a/lib/node_modules/@stdlib/utils/map4d/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/map4d/docs/types/test.ts @@ -28,6 +28,17 @@ function clbk( v: number ): number { return v; } +/** +* Callback function. +* +* @param v - argument +* @param indices - element indices +* @returns result +*/ +function clbki( v: number, indices: Array ): number { + return v + indices[ 0 ]; +} + // TESTS // @@ -40,6 +51,7 @@ function clbk( v: number ): number { map4d( arr, clbk ); // $ExpectType number[][][][] map4d( arr, clbk, {} ); // $ExpectType number[][][][] + map4d( arr, clbki ); // $ExpectType number[][][][] } // The compiler throws an error if the function is provided a first argument other than a four-dimensional nested array... diff --git a/lib/node_modules/@stdlib/utils/map5d/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/map5d/docs/types/index.d.ts index 2b5b882f2f80..335d08ed8ba4 100644 --- a/lib/node_modules/@stdlib/utils/map5d/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/map5d/docs/types/index.d.ts @@ -49,7 +49,7 @@ type Unary = ( this: V, value: T ) => U; * @param indices - current array element indices * @returns result */ -type Binary = ( this: V, value: T, index: number ) => U; +type Binary = ( this: V, value: T, indices: Array ) => U; /** * Callback invoked for each array element. @@ -59,7 +59,7 @@ type Binary = ( this: V, value: T, index: number ) => U; * @param arr - array * @returns result */ -type Ternary = ( this: V, value: T, index: number, arr: Array5D ) => U; +type Ternary = ( this: V, value: T, indices: Array, arr: Array5D ) => U; /** * Callback invoked for each array element. diff --git a/lib/node_modules/@stdlib/utils/map5d/docs/types/test.ts b/lib/node_modules/@stdlib/utils/map5d/docs/types/test.ts index 194a01cd6abb..9e404d7042d6 100644 --- a/lib/node_modules/@stdlib/utils/map5d/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/map5d/docs/types/test.ts @@ -28,6 +28,17 @@ function clbk( v: number ): number { return v; } +/** +* Callback function. +* +* @param v - argument +* @param indices - element indices +* @returns result +*/ +function clbki( v: number, indices: Array ): number { + return v + indices[ 0 ]; +} + // TESTS // @@ -40,6 +51,7 @@ function clbk( v: number ): number { map5d( arr, clbk ); // $ExpectType number[][][][][] map5d( arr, clbk, {} ); // $ExpectType number[][][][][] + map5d( arr, clbki ); // $ExpectType number[][][][][] } // The compiler throws an error if the function is provided a first argument other than a five-dimensional nested array...