属性 'data' 在 Redux 操作中的类型 'void' 上不存在

Property 'data' does not exist on type 'void' in Redux action

在尝试执行此操作时,当我在后端获得正确的响应数据时,data 变量返回未定义。我也收到 TS 错误 Property 'data' does not exist on type 'void'

action/churches.js

export const getChurchesBySearch = (searchQuery) => async (dispatch) => {
  try {
    const { data } = await apis.getChurchesBySearch(searchQuery);
    dispatch({ type: "FETCH_BY_SEARCH", payload: data });

  } catch (error) {
    console.log(error.message);
  }
};

就像我提到的,后端返回了正确的响应,但是当将它分配给 data 时,data 是未定义的。

这是其他文件:
apis/churches.js

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

controller/churches.js

export const getChurchesBySearch = async (req, res) => {
  const { city, denom } = req.query;
  try {
    const churches = await Church.find({
      $or: [{ city: city }, { denom: denom }],
    }).sort({ attend: -1 });
    res.status(200).json(churches);
  } catch (error) {
    res.status(404).json({ message: error.message });
  }
};

您在 getChurchesBySearch 函数中缺少 return 语句。

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