From 0d01e659a1bfd9451152daf5ea6996ec60569cd9 Mon Sep 17 00:00:00 2001 From: zetaloop Date: Fri, 20 Feb 2026 20:48:43 +0800 Subject: [PATCH] refactor: strengthen type modeling with discriminated unions --- lib/types.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/types.ts b/lib/types.ts index 4e76434..5e7cd98 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -15,7 +15,7 @@ export interface Game { id: string name: string icon: string - category: string + category: "MOBA" | "FPS" | "动作" | "RPG" } export interface PlayerService { @@ -26,7 +26,7 @@ export interface PlayerService { title: string description: string price: number - unit: string + unit: "局" | "星" | "次" rankRange?: string availability: string[] } @@ -126,10 +126,8 @@ export interface Dispute { createdAt: string } -export interface ChatSession { +interface BaseChatSession { id: string - type: "consultation" | "order" - orderId?: string participants: { id: string; name: string; avatar: string }[] lastMessage?: string lastMessageAt?: string @@ -137,6 +135,18 @@ export interface ChatSession { readonly: boolean } +export interface OrderChatSession extends BaseChatSession { + type: "order" + orderId: string +} + +export interface ConsultationChatSession extends BaseChatSession { + type: "consultation" + orderId?: never +} + +export type ChatSession = OrderChatSession | ConsultationChatSession + export interface ChatMessage { id: string sessionId: string