You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Redux action出现Property 'data' does not exist on type 'void'报错如何解决

问题根因

你遇到的TS报错Property 'data' does not exist on type 'void'、解构得到的data为undefined的核心原因,都出在apis/churches.js的接口封装逻辑上:该函数没有返回axios.get的执行结果,调用后默认返回值为undefined(类型标注为void),哪怕后端接口响应正常,前端也拿不到返回的响应对象,自然无法解构出data属性。

修复方案

修改apis/churches.js中的getChurchesBySearch函数,新增return关键字返回axios请求的Promise对象即可:

export const getChurchesBySearch = (searchQuery) => {
  console.log(searchQuery.city);
  // 新增return返回axios请求结果
  return axios.get(
    `${url}/search?city=${searchQuery.city}&denom=${searchQuery.denom}`
  );
};

也可以简写为箭头函数隐式返回的形式:

export const getChurchesBySearch = (searchQuery) => 
  axios.get(
    `${url}/search?city=${searchQuery.city}&denom=${searchQuery.denom}`
  );

验证说明

修复后apis.getChurchesBySearch会返回标准Promise对象,await后可以拿到完整的axios响应实例,即可正常解构出data字段,TS类型报错也会同步消失。

内容的提问来源于stack exchange,提问作者R. West

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 13:54:06