anvaka / ngraph.graph

Graph data structure in JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

forEachNode typing not quite correct

lordnox opened this issue · comments

As the forEachNode loop will stop when returning true

ngraph.graph/index.js

Lines 520 to 524 in b5e768a

for (var i = 0; i < keys.length; ++i) {
if (callback(nodes[keys[i]])) {
return true; // client doesn't want to proceed. Return.
}
}

The typing of forEachNode should be amended:

/** To stop the iteration return true in the callback */
forEachNode: (callbackPerNode: (node: Node<NodeData>) => void | undefined | null | boolean) => void

This would allow the use of the function as described in the readme:

g.forEachNode(function(node){
    console.log(node.id, node.data);
});

Typescript will fail here as the return value is undefined and not boolean

Tobias, thank you for noticing it and fixing it!

Your fix should be available starting from v19.0.1