2***@qq.com
2***@qq.com
  • 发布:2025-06-14 09:29
  • 更新:2025-06-14 09:29
  • 阅读:16

后端返回的数据有一个空数组,转换类型时报错

分类:uni-app x
export type ArticleItem = {  
  id: number;  
  user_id: number;  
  title: string;  
  images: any[] | string[];  
  url: string;  
  category_id: number;  
  topic_id: number;  
  share_count: number;  
  ding_count: number;  
  cai_count: number;  
  comment_count: number;  
  read_count: number;  
  collect_count: number;  
  create_time: string;  
  update_time: string;  
  name: string;  
  avatar: string | null;  
  user_status: number;  
  topic_name: any | null;  
  user_support_action: string;  
  isfollow: boolean;  
}  
 const data = [  
      {  
        "id": 1920,  
        "user_id": 2274,  
        "title": "你好",  
        "images": [  
          "http://sqapi2.dishawang.com/storage/uploads/259ca58f52fdc560af8830b8427f1a86.jpg"  
        ],  
        "url": "",  
        "category_id": 3,  
        "topic_id": 17,  
        "share_count": 0,  
        "ding_count": 2,  
        "cai_count": 2,  
        "comment_count": 0,  
        "read_count": 9,  
        "collect_count": 2,  
        "create_time": "2025-04-21 23:00:25",  
        "update_time": "2025-06-13 09:37:24",  
        "name": "173****5563",  
        "avatar": null,  
        "user_status": 1,  
        "topic_name": "总有一句话贼走心",  
        "user_support_action": "",  
        "isfollow": false  
      },  
      {  
        "id": 1879,  
        "user_id": 2021,  
        "title": "哈哈哈",  
        "images": ["http://sqapi2.dishawang.com/storage/uploads/259ca58f52fdc560af8830b8427f1a86.jpg"],  
        "url": "",  
        "category_id": 3,  
        "topic_id": 17,  
        "share_count": 0,  
        "ding_count": 4,  
        "cai_count": 0,  
        "comment_count": 0,  
        "read_count": 24,  
        "collect_count": 1,  
        "create_time": "2024-09-22 22:43:54",  
        "update_time": "2025-04-04 15:06:00",  
        "name": "131****3835",  
        "avatar": null,  
        "user_status": 1,  
        "topic_name": "总有一句话贼走心",  
        "user_support_action": "",  
        "isfollow": false  
      },  
      {  
        "id": 1878,  
        "user_id": 2016,  
        "title": "测试帖子",  
        "images": [  
          "https://sqapi2.dishawang.com/storage/uploads/c6f495bb4c2392d8a7e0b3d81f394b17.jpg",  
          "https://sqapi2.dishawang.com/storage/uploads/a61ececacb9bdf21598aaaf6d7906550.jpg",  
          "https://sqapi2.dishawang.com/storage/uploads/5b9796e99c787d8712c32a4e0b5ab00f.jpg"  
        ],  
        "url": "",  
        "category_id": 2,  
        "topic_id": 17,  
        "share_count": 0,  
        "ding_count": 5,  
        "cai_count": 4,  
        "comment_count": 2,  
        "read_count": 229,  
        "collect_count": 3,  
        "create_time": "2024-09-08 21:36:55",  
        "update_time": "2025-06-02 23:53:22",  
        "name": "哈哈哈",  
        "avatar": "https://sqapi2.dishawang.com/storage/avatar/66cf34ca2e469.png",  
        "user_status": 1,  
        "topic_name": "总有一句话贼走心",  
        "user_support_action": "",  
        "isfollow": false  
      },  
      {  
        "id": 1882,  
        "user_id": 2132,  
        "title": "哈哈哈",  
        "images": [],  
        "url": "",  
        "category_id": 2,  
        "topic_id": 17,  
        "share_count": 0,  
        "ding_count": 7,  
        "cai_count": 4,  
        "comment_count": 32,  
        "read_count": 75,  
        "collect_count": 1,  
        "create_time": "2024-09-29 16:41:34",  
        "update_time": "2025-05-31 23:35:27",  
        "name": "177****7521",  
        "avatar": null,  
        "user_status": 1,  
        "topic_name": "总有一句话贼走心",  
        "user_support_action": "",  
        "isfollow": false  
      }  
    ]  
    let resData = JSON.parse<ArticleItem>(JSON.stringify(data));  
      console.log('resData: ', resData);  

编译失败
09:18:22.177 ‌error: Not enough information to infer type variable E‌
报的是这个images为空数组的这里

2025-06-14 09:29 负责人:无 分享
已邀请:

要回复问题请先登录注册