Showing
3 changed files
with
18 additions
and
21 deletions
| 1 | -import { UserData } from "../user/types"; | ||
| 2 | - | ||
| 3 | /** | 1 | /** |
| 4 | * 방 리스트에서 사용됩니다. | 2 | * 방 리스트에서 사용됩니다. |
| 5 | */ | 3 | */ |
| ... | @@ -19,3 +17,7 @@ export interface RoomInfo { | ... | @@ -19,3 +17,7 @@ export interface RoomInfo { |
| 19 | maxUsers: number; | 17 | maxUsers: number; |
| 20 | users: UserData[]; | 18 | users: UserData[]; |
| 21 | } | 19 | } |
| 20 | + | ||
| 21 | +export interface UserData { | ||
| 22 | + username: string; | ||
| 23 | +} | ... | ... |
| 1 | +import { RoomDescription, RoomInfo } from "./dataType"; | ||
| 2 | + | ||
| 1 | // 서버로 들어오는 메세지 타입을 정의합니다. | 3 | // 서버로 들어오는 메세지 타입을 정의합니다. |
| 2 | // 'result' 속성은 서버 요청 결과에만 포함되는 특별한 속성입니다. | 4 | // 'result' 속성은 서버 요청 결과에만 포함되는 특별한 속성입니다. |
| 3 | export interface ServerInboundMessageMap { | 5 | export interface ServerInboundMessageMap { |
| ... | @@ -8,25 +10,13 @@ export interface ServerInboundMessageMap { | ... | @@ -8,25 +10,13 @@ export interface ServerInboundMessageMap { |
| 8 | 10 | ||
| 9 | // 방 목록을 요청합니다. | 11 | // 방 목록을 요청합니다. |
| 10 | roomList: { | 12 | roomList: { |
| 11 | - result: { | 13 | + result: RoomDescription[]; |
| 12 | - uuid: string; | ||
| 13 | - name: string; | ||
| 14 | - currentUsers: number; | ||
| 15 | - maxUsers: number; | ||
| 16 | - }[]; | ||
| 17 | }; | 14 | }; |
| 18 | 15 | ||
| 19 | // 방에 접속합니다. | 16 | // 방에 접속합니다. |
| 20 | joinRoom: { | 17 | joinRoom: { |
| 21 | uuid: string; | 18 | uuid: string; |
| 22 | - result: { | 19 | + result: RoomInfo; |
| 23 | - uuid: string; | ||
| 24 | - name: string; | ||
| 25 | - maxUsers: number; | ||
| 26 | - users: { | ||
| 27 | - username: string; | ||
| 28 | - }[]; | ||
| 29 | - }; | ||
| 30 | }; | 20 | }; |
| 31 | 21 | ||
| 32 | // 방에서 나갑니다. | 22 | // 방에서 나갑니다. |
| ... | @@ -131,8 +121,16 @@ export interface ServerOutboundMessageMap { | ... | @@ -131,8 +121,16 @@ export interface ServerOutboundMessageMap { |
| 131 | }; | 121 | }; |
| 132 | } | 122 | } |
| 133 | 123 | ||
| 134 | -export interface ServerResponse<T> { | 124 | +export type ServerInboundMessage<Key extends keyof ServerInboundMessageMap> = |
| 125 | + Omit<ServerInboundMessageMap[Key], "result">; | ||
| 126 | + | ||
| 127 | +export interface ServerResponse<Key extends keyof ServerInboundMessageMap> { | ||
| 135 | ok: boolean; | 128 | ok: boolean; |
| 136 | reason?: string; | 129 | reason?: string; |
| 137 | - result?: T; | 130 | + result?: "result" extends keyof ServerInboundMessageMap[Key] |
| 131 | + ? ServerInboundMessageMap[Key]["result"] | ||
| 132 | + : never; | ||
| 138 | } | 133 | } |
| 134 | + | ||
| 135 | +export type ServerOutboundMessage<Key extends keyof ServerOutboundMessageMap> = | ||
| 136 | + ServerOutboundMessageMap[Key]; | ... | ... |
server/user/types.ts
deleted
100644 → 0
-
Please register or login to post a comment