pokemon-showdown/test/server
Waleed Hassan f7e024e009
Allow safer and exact type retrieval of Room#game (#6315)
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
2020-02-03 05:09:37 -08:00
..
chat-plugins Rename Room#id -> Room#roomid, User#userid -> User#id (#5826) 2019-10-03 18:57:38 +10:00
chat.js Test: Update folder structure to match source code (#5436) 2019-04-14 23:57:06 +09:30
ladders.js Rename Room#id -> Room#roomid, User#userid -> User#id (#5826) 2019-10-03 18:57:38 +10:00
room-battle.js toId -> toID 2019-05-12 17:53:01 -07:00
rooms.js Allow safer and exact type retrieval of Room#game (#6315) 2020-02-03 05:09:37 -08:00
sockets.js Test: Update folder structure to match source code (#5436) 2019-04-14 23:57:06 +09:30
users.js Stop using Rooms.lobby in tests (#6316) 2020-01-26 13:41:39 -08:00