Skip to content

Commit

Permalink
Fix the docs and types of forEach, which returns void (see #2840)
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Nov 18, 2022
1 parent 8aafc2d commit b050d5e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ Tom Hickson <[email protected]>
dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Markel F <[email protected]>
Lazersmoke <[email protected]>
Alan Everett <[email protected]>
SungJinWoo-SL <[email protected]>
Nick Ewing <[email protected]>
jos <[email protected]>
Expand Down Expand Up @@ -199,7 +198,6 @@ FelixSelter <[email protected]>
Hansuku <[email protected]>
Windrill <[email protected]>
Carl Osterwisch <[email protected]>
Lucas Egidio <[email protected]>
Isaac B <[email protected]>
Ajinkya Chikhale <[email protected]>
Abdullah Adeel <[email protected]>
Expand All @@ -210,5 +208,7 @@ Glen Whitney <glen@studioinfinity>
Johannes Feist <[email protected]>
Alexandre Alves <[email protected]>
Samuel TLG <[email protected]>
thatcomputerguy0101 <[email protected]>
Lucas Egidio <[email protected]>

# Generated by tools/update-authors.js
3 changes: 2 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/expressions/expression_trees.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/function/matrix/forEach.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
})
Expand Down
6 changes: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -5385,7 +5385,7 @@ declare namespace math {
this: MathJsChain<T>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
callback: (value: any, index: any, matrix: T) => void
): MathJsChain<T>
): void

/**
* Calculate the inverse of a square matrix.
Expand Down

0 comments on commit b050d5e

Please sign in to comment.