refactor(game): remove as-any casts in cube + snapshot paths (Phase 9 of #96) - #144
Merged
nodots merged 1 commit intoJul 15, 2026
Conversation
… (Phase 9 of #96) cube.ts: drop all 5 'as any' casts. - offeredThisTurnBy is on BaseCube, so the cast was unnecessary. - rollForStartValue is on BasePlayerProps (optional); the two player-copy casts become documented non-null assertions (rolling/inactive player types require the field). - the acceptDouble return 'as any' narrows to a commented 'as unknown as BackgammonGameRolling' (spread yields a generic players array TS can't narrow to the tuple). turnFlow.ts: remove the undo-snapshot casts in move() and executeAndRecalculate() -- game.activePlay and undo.frames are typed now (since the Phase 2 types fix), so 'const ap: any = (game as any)...' plus the JSON fallback 'as any' are gone. index.ts: comment the gnuPositionId getter's 'this as any' (Game class vs BackgammonGame union). Deferred: turnFlow still has ~30 '(move as any).x =' casts in the sanitization/recalculation loops. Removing those requires rebuilding move objects immutably instead of mutating in place -- a behavior-sensitive change left for a dedicated pass now that turnFlow has ~76% coverage. No behavior change. Core: 518 passed / 12 skipped, tsc -b clean. Refs #96
Base automatically changed from
refactor/game-decomp-phase8-coverage
to
refactor/game-decomp-phase7-facade
July 15, 2026 18:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 9 of the epic (#133) —
as anyremoval (#96)Stacked on #143 (Phase 8). Retarget to
developmentas parents merge.Continues the
#96cast removal beyond the undo slice (done in Phase 2).cube.ts — all 5
as anyremovedofferedThisTurnByis declared onBaseCube, so(game.cube as any).offeredThisTurnBywas unnecessary.rollForStartValueis onBasePlayerProps(optional) but required on the rolling/inactive player types → the two player-copy casts become documented non-null assertions.acceptDoublereturnas anynarrows to a commentedas unknown as BackgammonGameRolling(the spread yields a generic players array TS can't narrow to the tuple shape).turnFlow.ts — undo-snapshot casts removed
game.activePlayandundo.framesare typed now (since the Phase 2 types fix), so theconst ap: any = (game as any).activePlayblocks inmove()andexecuteAndRecalculate()— plus their JSON-fallbackas any— are gone, replaced by a typedap.undo ?? (ap.undo = { frames: [] }).index.ts
The
gnuPositionIdgetter'sthis as anynow carries the required explanatory comment (Game class vsBackgammonGameunion).Deferred
turnFlow.tsstill has ~30(move as any).x =casts in the sanitization/recalculation loops. Removing them means rebuilding move objects immutably instead of mutating in place — a behavior-sensitive change in the hottest game path, left for a dedicated pass now thatturnFlowhas ~76% coverage.Verification
tsc -b --forcecleannpx jest: 518 passed / 12 skipped, unchangedRefs #96