enum OpCode { PING, HELLO, MOVE, } type PingEvent = Record; type HelloEvent = { name: string; }; type MoveEvent = { x: number; y: number; }; type OpArgsMapping = { [OpCode.PING]: PingEvent; [OpCode.HELLO]: HelloEvent; [OpCode.MOVE]: MoveEvent; }; class WebSocketClient { public send( op: TOp, args: TArgs, ) { // ... } } function main1() { const client = new WebSocketClient(); client.send(OpCode.PING, {}); }