Skip to content

refactor(game): remove as-any casts in cube + snapshot paths (Phase 9 of #96) - #144

Merged
nodots merged 1 commit into
refactor/game-decomp-phase7-facadefrom
refactor/game-decomp-phase9-casts
Jul 15, 2026
Merged

refactor(game): remove as-any casts in cube + snapshot paths (Phase 9 of #96)#144
nodots merged 1 commit into
refactor/game-decomp-phase7-facadefrom
refactor/game-decomp-phase9-casts

Conversation

@nodots

@nodots nodots commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Phase 9 of the epic (#133) — as any removal (#96)

Stacked on #143 (Phase 8). Retarget to development as parents merge.

Continues the #96 cast removal beyond the undo slice (done in Phase 2).

cube.ts — all 5 as any removed

  • offeredThisTurnBy is declared on BaseCube, so (game.cube as any).offeredThisTurnBy was unnecessary.
  • rollForStartValue is on BasePlayerProps (optional) but required on the rolling/inactive player types → the two player-copy casts become documented non-null assertions.
  • The acceptDouble return as any narrows to a commented as 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.activePlay and undo.frames are typed now (since the Phase 2 types fix), so the const ap: any = (game as any).activePlay blocks in move() and executeAndRecalculate() — plus their JSON-fallback as any — are gone, replaced by a typed ap.undo ?? (ap.undo = { frames: [] }).

index.ts

The gnuPositionId getter's this as any now carries the required explanatory comment (Game class vs BackgammonGame union).

Deferred

turnFlow.ts still 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 that turnFlow has ~76% coverage.

Verification

  • tsc -b --force clean
  • npx jest: 518 passed / 12 skipped, unchanged

Refs #96

… (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
@nodots
nodots merged commit a4b32ac into refactor/game-decomp-phase7-facade Jul 15, 2026
@nodots
nodots deleted the refactor/game-decomp-phase9-casts branch July 15, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant