diff --git a/lib/agent/runtime.ts b/lib/agent/runtime.ts index 83c951b..8134a54 100644 --- a/lib/agent/runtime.ts +++ b/lib/agent/runtime.ts @@ -167,7 +167,7 @@ export class Runtime { // If the parent does not exist or the key does not exist // then delete the sensor if (parent == null || !Object.hasOwn(parent, Path.basename(p))) { - this.subscriptions[p].unsubscribe(); + this.subscriptions[p]!.unsubscribe(); delete this.subscriptions[p]; } }); diff --git a/lib/dag.ts b/lib/dag.ts index 5654eff..9822337 100644 --- a/lib/dag.ts +++ b/lib/dag.ts @@ -208,6 +208,7 @@ function traverseCombine( assert(ends.length > 0, 'Malformed DAG found, empty Fork node'); const [res] = ends; + assert(res != null); // Typescript is not smart enough to figure out that res cannot be undefined assert(!res.done, 'Malformed DAG found, disconnected fork branch'); // Combine the results from the branches passing the diff --git a/lib/planner/findPlan.ts b/lib/planner/findPlan.ts index 5ede66a..e3f6705 100644 --- a/lib/planner/findPlan.ts +++ b/lib/planner/findPlan.ts @@ -134,7 +134,7 @@ function findConflict( const unique = new Map(); for (let i = 0; i < ops.length; i++) { - const patches = ops[i]; + const patches = ops[i]!; for (const o of patches) { for (const [path, [index, op]] of unique.entries()) { @@ -216,7 +216,7 @@ function tryParallel( // having the fork and empty node, so we need to remove the empty node // and connect the last action in the branch directly to the existing plan if (results.length === 1) { - const branch = results[0]; + const branch = results[0]!; // Find the first node for which the next element is the // empty node created earlier const last = DAG.find( diff --git a/lib/testing/builder.ts b/lib/testing/builder.ts index 8081a19..a7838cb 100644 --- a/lib/testing/builder.ts +++ b/lib/testing/builder.ts @@ -68,7 +68,7 @@ function fromFork(branches: Branch[]): [Node | null, Node | null] { // If there is only a branch, call the branch method if (branches.length === 1) { - return fromBranch(branches[0]); + return fromBranch(branches[0]!); } // For multiple branches, create a fork and diff --git a/lib/testing/mermaid.ts b/lib/testing/mermaid.ts index 80c80c9..ad1dd3c 100644 --- a/lib/testing/mermaid.ts +++ b/lib/testing/mermaid.ts @@ -66,10 +66,11 @@ function fromNode( if (DAG.isFork(node)) { const actions = node.next.filter(PlanAction.is); if (actions.length > 0) { + const [first] = actions; // In this case we just use id of the first action in the // fork as we really should not have multiple fork nodes in the // diagram pointing to the same actions - return DiagramNode.fromId(`j${actions[0].id.substring(0, 7)}`); + return DiagramNode.fromId(`j${first!.id.substring(0, 7)}`); } const forks = node.next.filter(DAG.isFork); @@ -156,7 +157,7 @@ class DiagramAdjacency { // The official parent of a node is the last parent // in the list - return p[p.length - 1]; + return p[p.length - 1]!; } getAll(node: DiagramNode): DiagramNode[] { @@ -260,7 +261,10 @@ class Diagram { ends.forEach(([_, p]) => this.graph.push(` ${p} --> ${join}`)); this.graph.push(` ${join}:::selected`); - const [first] = ends[0]; + const [end] = ends; + assert(end != null); + + const [first] = end; return this.drawPlan(first.next, join); } diff --git a/lib/utils/deep-equal.ts b/lib/utils/deep-equal.ts index abd84bc..ed60726 100644 --- a/lib/utils/deep-equal.ts +++ b/lib/utils/deep-equal.ts @@ -1,3 +1,5 @@ +import { assert } from '../assert'; + function isObject(value: unknown): value is object { return typeof value === 'object' && value !== null; } @@ -33,6 +35,11 @@ export function deepEqual(value: T, other: T): boolean { const [vProps, oProps] = [value, other].map( (a) => Object.getOwnPropertyNames(a) as Array, ); + + // This will never fail but it prevents the compiler from + // complaining + assert(vProps != null && oProps != null); + if (vProps.length !== oProps.length) { // If the property lists are different lengths we don't need // to check any further diff --git a/package.json b/package.json index 66d1c53..5017458 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "tar-stream": "3.0.0", "ts-node": "^10.9.1", "tsconfig-paths": "^4.1.1", - "typescript": "^5.5.2" + "typescript": "^5.5.4" }, "dependencies": { "mahler-wasm": "^0.1.0" diff --git a/tsconfig.json b/tsconfig.json index 94bbb39..160af53 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,6 +12,7 @@ "target": "es2022", "declaration": true, "skipLibCheck": true, + "noUncheckedIndexedAccess": true, "paths": { "mahler": [ "lib/index.ts"