From 5ccacd7a6587f4a10ca210e1882d0dcb91b06266 Mon Sep 17 00:00:00 2001 From: rory Date: Mon, 7 Sep 2026 11:49:20 -0700 Subject: [PATCH] Remove unsafe type assertions in StateMachine Type state as Current instead of ReadonlyDeep so constructor assignment and transition lookup need no casts. --- lib/StateMachine.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/StateMachine.ts b/lib/StateMachine.ts index 507e0a3cc..b2ad91f03 100644 --- a/lib/StateMachine.ts +++ b/lib/StateMachine.ts @@ -1,5 +1,3 @@ -import type {ReadonlyDeep} from 'type-fest'; - /** * A directed transition graph keyed by state name. * Use `as const` when defining a graph so illegal transitions are caught at compile time. @@ -34,13 +32,13 @@ type TransitionsFrom { - /** The current state. Deeply readonly and owned by this state machine instance. */ - readonly state: ReadonlyDeep; + /** The current state. Owned by this state machine instance. */ + readonly state: Current; private readonly transitions: Graph; constructor(currentState: Current, transitions: Graph) { - this.state = currentState as ReadonlyDeep; + this.state = currentState; this.transitions = transitions; Object.freeze(this); } @@ -50,7 +48,7 @@ class StateMachine>(target: Target): StateMachine { - const validTargets = this.transitions[this.state as Current]; + const validTargets = this.transitions[this.state]; if (!validTargets?.includes(target)) { throw new Error(`Illegal transition from "${String(this.state)}" to "${String(target)}"`); }