From b050d5ed5d2c9f35900a68d350e84bac1ccb4a82 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Fri, 18 Nov 2022 10:18:59 +0100 Subject: [PATCH] Fix the docs and types of `forEach`, which returns `void` (see #2840) --- AUTHORS | 4 ++-- HISTORY.md | 3 ++- docs/expressions/expression_trees.md | 6 +++--- src/function/matrix/forEach.js | 2 +- types/index.d.ts | 6 +++--- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index ae1ceb58be..785d8df1fe 100644 --- a/AUTHORS +++ b/AUTHORS @@ -133,7 +133,6 @@ Tom Hickson dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Markel F Lazersmoke -Alan Everett SungJinWoo-SL <56172528+SungJinWoo-SL@users.noreply.github.com> Nick Ewing jos @@ -199,7 +198,6 @@ FelixSelter <55546882+FelixSelter@users.noreply.github.com> Hansuku <1556207795@qq.com> Windrill Carl Osterwisch -Lucas Egidio Isaac B <66892358+isaacbyr@users.noreply.github.com> Ajinkya Chikhale <86607732+ajinkyac03@users.noreply.github.com> Abdullah Adeel <64294045+mabdullahadeel@users.noreply.github.com> @@ -210,5 +208,7 @@ Glen Whitney Johannes Feist Alexandre Alves <91118126+AlexandreAlvesDB@users.noreply.github.com> Samuel TLG +thatcomputerguy0101 +Lucas Egidio <12188889+egidioln@users.noreply.github.com> # Generated by tools/update-authors.js diff --git a/HISTORY.md b/HISTORY.md index a1dade1ac1..1eed04943a 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -8,7 +8,8 @@ Thanks @egidioln. - Fix #2825 partly: improve simplifying operations on constants in non-commutative contexts (#2827). Thanks @samueltlg. -- Fix #2840: a bug in the type definition of `Node.traverse`. +- Fix #2840: a bug in the docs and type definitions of `Node.traverse` and + `Node.forEach`, they do return `void`. # 2022-11-07, 11.3.3 diff --git a/docs/expressions/expression_trees.md b/docs/expressions/expression_trees.md index 29589a1332..9dfc24a125 100644 --- a/docs/expressions/expression_trees.md +++ b/docs/expressions/expression_trees.md @@ -93,10 +93,10 @@ All nodes have the following methods: // returns an array with two entries: two SymbolNodes 'x' ``` -- `forEach(callback: function) : Node[]` +- `forEach(callback: function) : void` Execute a callback for each of the child nodes of this node. The `callback` - function is called as `callback(child: Node, path: string, parent: Node)`. + function is called as `callback(child: Node, path: string, parent: Node): void`. Parameter `path` is a string containing a relative JSON Path. See also `traverse`, which is a recursive version of `forEach`. @@ -207,7 +207,7 @@ All nodes have the following methods: transformed.toString() // returns '3 ^ 2 + 5 * 3' ``` -- `traverse(callback)` +- `traverse(callback: function): void` Recursively traverse all nodes in a node tree. Executes given callback for this node and each of its child nodes. Similar to `Array.forEach`, except diff --git a/src/function/matrix/forEach.js b/src/function/matrix/forEach.js index ac76980316..73fd7cace7 100644 --- a/src/function/matrix/forEach.js +++ b/src/function/matrix/forEach.js @@ -33,7 +33,7 @@ export const createForEach = /* #__PURE__ */ factory(name, dependencies, ({ type 'Array, function': _forEach, 'Matrix, function': function (x, callback) { - return x.forEach(callback) + x.forEach(callback) } }) }) diff --git a/types/index.d.ts b/types/index.d.ts index 06a54f96bd..aa8b3ed53a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -4020,8 +4020,8 @@ declare namespace math { */ forEach( // eslint-disable-next-line @typescript-eslint/no-explicit-any - callback: (node: MathNode, path: string, parent: MathNode) => any - ): MathNode[] + callback: (node: MathNode, path: string, parent: MathNode) => void + ): void /** * Transform a node. Creates a new MathNode having it’s child's be the @@ -5385,7 +5385,7 @@ declare namespace math { this: MathJsChain, // eslint-disable-next-line @typescript-eslint/no-explicit-any callback: (value: any, index: any, matrix: T) => void - ): MathJsChain + ): void /** * Calculate the inverse of a square matrix.