refactor: strengthen type modeling with discriminated unions
This commit is contained in:
+15
-5
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user