From 435f797750693b9ca570e11147588ca5daa4356a Mon Sep 17 00:00:00 2001 From: josedario87 Date: Sat, 5 Jul 2025 14:59:16 -0600 Subject: [PATCH] fix: Resolve TypeScript compilation errors - Add explicit types for allPlayers array and forEach parameters - Initialize Schema properties with default values - Fix arithmetic operation types with null coalescing - Resolve duplicate 'clients' property in object literal --- server/src/app.config.ts | 4 ++-- server/src/rooms/GameRoom.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/server/src/app.config.ts b/server/src/app.config.ts index 7ffb497..47d0d12 100644 --- a/server/src/app.config.ts +++ b/server/src/app.config.ts @@ -65,7 +65,7 @@ export default config({ let totalPlayers = 0; let activeGames = 0; const gameRooms = []; - const allPlayers = []; + const allPlayers: any[] = []; for (const room of rooms) { if (room.name === 'game') { @@ -88,7 +88,7 @@ export default config({ // Extract player information with their tokens if (roomData.state && roomData.state.players) { // Use forEach to iterate over MapSchema properly - roomData.state.players.forEach((player, playerId) => { + roomData.state.players.forEach((player: any, playerId: string) => { // Skip internal MapSchema properties if (playerId.startsWith('$') || playerId === 'deletedItems') { return; diff --git a/server/src/rooms/GameRoom.ts b/server/src/rooms/GameRoom.ts index 1618295..b794736 100644 --- a/server/src/rooms/GameRoom.ts +++ b/server/src/rooms/GameRoom.ts @@ -13,17 +13,17 @@ export class TokenInventory extends Schema { } export class TradeOffer extends Schema { - @type("string") id: string; - @type("string") offererId: string; - @type("string") targetId: string; + @type("string") id: string = ""; + @type("string") offererId: string = ""; + @type("string") targetId: string = ""; @type(TokenInventory) offering = new TokenInventory(); @type(TokenInventory) requesting = new TokenInventory(); @type("string") status: string = "pending"; // "pending" | "accepted" | "rejected" | "snatched" | "cancelled" } export class Player extends Schema { - @type("string") id: string; - @type("string") name: string; + @type("string") id: string = ""; + @type("string") name: string = ""; @type("string") producerRole: string = "turkey"; // "turkey" | "coffee" | "corn" @type(TokenInventory) tokens = new TokenInventory(); @type("number") points: number = 0; @@ -101,7 +101,7 @@ export class GameRoom extends Room { } private calculatePoints(player: Player): number { - const ownTokens = player.tokens[player.producerRole as keyof TokenInventory]; + const ownTokens = player.tokens[player.producerRole as keyof TokenInventory] || 0; const otherTokens = (player.tokens.turkey + player.tokens.coffee + player.tokens.corn) - ownTokens; return ownTokens * 1 + otherTokens * 2; } @@ -284,7 +284,7 @@ export class GameRoom extends Room { return { roomId: this.roomId, name: 'game', - clients: clients.length, + clientCount: clients.length, maxClients: this.maxClients, locked: this.locked, state: this.state,