Skip to content

Commit 013f68b

Browse files
committed
fix: generic type of graph argument accept any LinkProps in findNodes, getNode, getFirstNode
1 parent 08b6de8 commit 013f68b

4 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/utils/findNodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { NoInfer } from '../types.js';
55
* Returns all the nodes matching your function.
66
*/
77
export function findNodes<Node>(
8-
graph: Graph<Node>,
8+
graph: Graph<Node, any>,
99
fn: (node: NoInfer<Node>) => boolean,
1010
): Node[] {
1111
const nodes: Node[] = [];

src/utils/getFirstNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { NoInfer } from '../types.js';
55
* Return the first node matching your function and throws if none is found.
66
*/
77
export function getFirstNode<Node>(
8-
graph: Graph<Node>,
8+
graph: Graph<Node, any>,
99
fn: (node: NoInfer<Node>) => boolean,
1010
): Node {
1111
for (const node of graph.nodes) {

src/utils/getNode.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,13 @@ describe('getNode', () => {
3232

3333
expect(() => getNode(graph, (n) => n.type === 'foo')).toThrowError();
3434
});
35+
36+
it.skip('should not trigger a type error when the link props are set', ({ expect }) => {
37+
const graph = new Graph<Node, { foo: string }>();
38+
const node1 = { id: '1', type: 'foo' };
39+
40+
graph.addNode(node1);
41+
42+
expect(getNode(graph, (n) => n.id === '1')).toEqual(node1);
43+
});
3544
});

src/utils/getNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { NoInfer } from '../types.js';
55
* Return the node matching your function. Throws if none is found or if more than one node if found.
66
*/
77
export function getNode<Node>(
8-
graph: Graph<Node>,
8+
graph: Graph<Node, any>,
99
fn: (node: NoInfer<Node>) => boolean,
1010
): Node {
1111
const foundNodes: Node[] = [];

0 commit comments

Comments
 (0)