Bladeren bron

✨ feat(goods-spec-selector): 新增商品接口类型定义并优化类型安全

- 新增 GoodsFromApi 接口类型,明确定义从API获取的商品数据结构
- 在 map 函数中为 goods 参数添加 GoodsFromApi 类型注解,提升代码类型安全性
yourname 1 maand geleden
bovenliggende
commit
5ef2e180da
1 gewijzigde bestanden met toevoegingen van 9 en 1 verwijderingen
  1. 9 1
      mini/src/components/goods-spec-selector/index.tsx

+ 9 - 1
mini/src/components/goods-spec-selector/index.tsx

@@ -11,6 +11,14 @@ interface SpecOption {
   image?: string
 }
 
+interface GoodsFromApi {
+  id: number
+  name: string
+  price: number
+  stock: number
+  imageFile?: { fullUrl: string }
+}
+
 interface SpecSelectorProps {
   visible: boolean
   onClose: () => void
@@ -61,7 +69,7 @@ export function GoodsSpecSelector({
           if (response.status === 200) {
             const data = await response.json()
             // 将子商品数据转换为规格选项格式
-            const childGoodsAsSpecs: SpecOption[] = data.data.map((goods) => ({
+            const childGoodsAsSpecs: SpecOption[] = data.data.map((goods: GoodsFromApi) => ({
               id: goods.id, // 子商品ID
               name: goods.name, // 子商品名称作为规格名称
               price: goods.price,