mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-05-20 14:08:15 -05:00
By adding a `getGame` function of type: ``` // null is returned if the gameids don't match // or the game doesn't exist getGame<T extends RoomGame>(constructor: new (...args: any[]) => T) => T | null ``` (Credits @urkerab and @whalemer for the function signature.) It allows refactoring previous code of: ``` if (room.game && room.game.gameid !== 'hangman') return; const game = room.game as Hangman; ``` to: ``` const game = room.getGame(Hangman); if (!game) return; ``` This has a couple of advantages: - TypeScript will throw an error if the if condition is not present. - In the new code, the template must extends `RoomGame` and be assignable to the same ID, so it's 100% typesafe |
||
|---|---|---|
| .. | ||
| chat-plugins | ||
| chat.js | ||
| ladders.js | ||
| room-battle.js | ||
| rooms.js | ||
| sockets.js | ||
| users.js | ||