refactor(server): type captureTally accumulators as PieceTally

Tighten the local byYou/byOpponent accumulators from the wider
Record<string, number> to PieceTally, matching the return type's fields
and preventing silent invalid-key writes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
claude (blind_chess)
2026-05-18 20:14:26 -04:00
parent ce36755a89
commit 3169995d7f
+3 -3
View File
@@ -1,4 +1,4 @@
import type { CaptureTally, Color } from '@blind-chess/shared'; import type { CaptureTally, Color, PieceTally } from '@blind-chess/shared';
import type { Game } from './state.js'; import type { Game } from './state.js';
/** /**
@@ -8,8 +8,8 @@ import type { Game } from './state.js';
* no live board state, no opponent positions. * no live board state, no opponent positions.
*/ */
export function captureTally(game: Game, viewer: Color): CaptureTally { export function captureTally(game: Game, viewer: Color): CaptureTally {
const byYou: Record<string, number> = {}; const byYou: PieceTally = {};
const byOpponent: Record<string, number> = {}; const byOpponent: PieceTally = {};
for (const rec of game.moveHistory) { for (const rec of game.moveHistory) {
const captured = rec.capturedPieceType; const captured = rec.capturedPieceType;
if (!captured) continue; if (!captured) continue;