#952·colyseus

[Bug]: `remoteRoomCall` does not infer the return type of the selected room method

Author: ColaFantaCreated Aug 9, 2026Updated Aug 10, 2026
Labels:bug: bug:eyes: triage

Bug description

matchMaker.remoteRoomCall() does not correctly infer the return type of the specific room method passed to it.

The current declaration is:

typescript
export declare function remoteRoomCall<TRoom = Room>(
  roomId: string,
  method: keyof TRoom,
  args?: any[],
): Promise<ExtractMethodOrPropertyType<TRoom, typeof method>>

Because method is typed as keyof TRoom, the selected method name is not preserved as the literal type 'getSeatsInfo'. As a result, the return type is calculated from all properties and methods of TRoom instead of only from TestRoom['getSeatsInfo'].

A possible fix is to introduce a separate generic parameter for the method key:

typescript
export declare function remoteRoomCall<
  TRoom = Room,
  TMethod extends keyof TRoom = keyof TRoom,
>(
  roomId: string,
  method: TMethod,
  args?: any[],
): Promise<ExtractMethodOrPropertyType<TRoom, TMethod>>

Steps to reproduce

  1. Define a room
typescript
class TestRoom extends Room {
  getSeatsInfo() {
    return [{ seatNo: 0, occupied: true }]
  }
}
  1. call using remoteRoomCall
typescript
const seatsInfo = await matchMaker.remoteRoomCall<TestRoom>(
  'room-id',
  'getSeatsInfo',
)
  1. the expected inferred type is:
typescript
{ seatNo: number; occupied: boolean }[]

However, the inferred type is a broad union containing the types of other TestRoom members, such as:

typescript
string |
number |
boolean |
Client |
ClockTimer |
... |
undefined

Environment & Versions

markdown
- OS: macOS
- Node.js: 22.x
- Package manager: pnpm
- `@colyseus/core`: 0.17.49
- TypeScript: 5.x