Skip to content

Commit 9c99039

Browse files
committed
build: set tsconfig noUncheckedIndexedAccess to true
1 parent 18617ad commit 9c99039

7 files changed

Lines changed: 20 additions & 11 deletions

File tree

src/Graph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class Graph<Node = string, LinkProps = never> {
6767
}
6868

6969
/**
70-
* Gets the adjacent node set for the given node.
70+
* Gets the adjacent nodes set for the given node.
7171
*/
7272
adjacent(node: Node): Set<Node> | undefined {
7373
return this.edges.get(node);

src/algorithms/depthFirstSearch/depthFirstSearch.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { invariant } from '../../invariant.js';
12
import type { NoInfer } from '../../types.js';
23
import type { DepthFirstSearchOptions } from './types.js';
34

@@ -20,18 +21,25 @@ export function depthFirstSearch<Node, LinkProps>(
2021

2122
if (includeSourceNodes) {
2223
for (let i = 0; i < sourceNodes.length; i++) {
23-
depthFirstVisit(graph, nodeList, visited, visiting, sourceNodes[i], opts);
24+
const sourceNode = sourceNodes[i];
25+
if (!sourceNode) continue;
26+
depthFirstVisit(graph, nodeList, visited, visiting, sourceNode, opts);
2427
}
2528
return nodeList;
2629
}
2730

2831
for (let i = 0; i < sourceNodes.length; i++) {
29-
visited.add(sourceNodes[i]);
32+
const sourceNode = sourceNodes[i];
33+
if (!sourceNode) continue;
34+
visited.add(sourceNode);
3035
}
3136

3237
for (let i = 0; i < sourceNodes.length; i++) {
38+
const sourceNode = sourceNodes[i];
39+
if (!sourceNode) continue;
40+
3341
graph
34-
.adjacent(sourceNodes[i])
42+
.adjacent(sourceNode)
3543
?.forEach((n) => depthFirstVisit(graph, nodeList, visited, visiting, n, opts));
3644
}
3745

src/algorithms/shortestPath/dijkstra.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function dijkstra<Node, LinkProps>(
1111
destination: NoInfer<Node>,
1212
) {
1313
const nodes = graph.nodes;
14-
const { d, p, q } = tracks;
14+
const { q } = tracks;
1515

1616
initializeSingleSource(nodes, tracks, source, destination);
1717
initializePriorityQueue(nodes, tracks);

src/algorithms/shortestPath/shortestPath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Graph } from '../../Graph.js';
2-
import { EdgeWeight, NoInfer } from '../../types.js';
2+
import { NoInfer } from '../../types.js';
33
import { dijkstra } from './dijkstra.js';
44
import { getPath } from './getPath.js';
55
import { TraversingTracks } from './types.js';

src/test-utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ export function checkSerialized(graph: Serialized<string>) {
99
expect(graph.nodes[1]).toEqual('b');
1010
expect(graph.nodes[2]).toEqual('c');
1111

12-
expect(graph.links[0].source).toEqual('a');
13-
expect(graph.links[0].target).toEqual('b');
14-
expect(graph.links[1].source).toEqual('b');
15-
expect(graph.links[1].target).toEqual('c');
12+
expect(graph.links[0]?.source).toEqual('a');
13+
expect(graph.links[0]?.target).toEqual('b');
14+
expect(graph.links[1]?.source).toEqual('b');
15+
expect(graph.links[1]?.target).toEqual('c');
1616
}
1717

1818
export function comesBefore(arr: ReadonlyArray<unknown>, a: unknown, b: unknown) {

src/utils/getNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ export function getNode<Node>(
2424
throw new Error('More than one node found.');
2525
}
2626

27-
return foundNodes[0];
27+
return foundNodes[0] as Node;
2828
}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"noImplicitAny": true,
1010
"noImplicitReturns": true,
1111
"noImplicitThis": true,
12+
"noUncheckedIndexedAccess": true,
1213
"downlevelIteration": true,
1314
"isolatedModules": true,
1415
"noEmit": true,

0 commit comments

Comments
 (0)