refactor: strengthen type modeling with discriminated unions

This commit is contained in:
zetaloop
2026-02-20 20:48:43 +08:00
parent 1f316c2f61
commit 0d01e659a1
+15 -5
View File
@@ -15,7 +15,7 @@ export interface Game {
id: string id: string
name: string name: string
icon: string icon: string
category: string category: "MOBA" | "FPS" | "动作" | "RPG"
} }
export interface PlayerService { export interface PlayerService {
@@ -26,7 +26,7 @@ export interface PlayerService {
title: string title: string
description: string description: string
price: number price: number
unit: string unit: "局" | "星" | "次"
rankRange?: string rankRange?: string
availability: string[] availability: string[]
} }
@@ -126,10 +126,8 @@ export interface Dispute {
createdAt: string createdAt: string
} }
export interface ChatSession { interface BaseChatSession {
id: string id: string
type: "consultation" | "order"
orderId?: string
participants: { id: string; name: string; avatar: string }[] participants: { id: string; name: string; avatar: string }[]
lastMessage?: string lastMessage?: string
lastMessageAt?: string lastMessageAt?: string
@@ -137,6 +135,18 @@ export interface ChatSession {
readonly: boolean 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 { export interface ChatMessage {
id: string id: string
sessionId: string sessionId: string