Browse Source

♻️ refactor(index): 优化微信代金券批次类型定义

- 移除手动定义的WechatCouponStock接口,改用RPC类型安全提取
- 使用InferResponseType从wechatCouponStockClient获取类型定义
- 简化类型转换,直接返回响应数据无需显式类型断言
yourname 3 months ago
parent
commit
1e5e14f880
1 changed files with 4 additions and 14 deletions
  1. 4 14
      mini/src/pages/index/index.tsx

+ 4 - 14
mini/src/pages/index/index.tsx

@@ -16,19 +16,9 @@ import type { InferResponseType } from 'hono/client'
 type AdvertisementResponse = InferResponseType<typeof publicAdvertisementClient.$get, 200>
 type Advertisement = AdvertisementResponse['data'][0]
 
-interface WechatCouponStock {
-  id: number
-  stockName: string
-  stockDescription: string
-  stockType: string
-  couponAmount: number
-  couponTotal: number
-  couponRemaining: number
-  beginTime: string
-  endTime: string
-  status: number
-  coverImage: string
-}
+// 使用RPC类型安全提取代金券批次响应类型
+type WechatCouponStockResponse = InferResponseType<typeof wechatCouponStockClient.$get, 200>
+type WechatCouponStock = WechatCouponStockResponse['data'][0]
 
 export default function IndexPage() {
   const queryClient = useQueryClient()
@@ -64,7 +54,7 @@ export default function IndexPage() {
       })
       if (response.status !== 200) throw new Error('获取批次失败')
       const result = await response.json()
-      return result.data as WechatCouponStock[]
+      return result.data
     },
   })