redux saga使用axios,TS里提示类型不匹配

api.tsx

import http from './http'

export default {
  common: {
    login(username: string, password: string) {
      return http.post('/common/login', {
        username,
        password,
      })
    },
}

其中http为axios配置封装后的导出。
然后在saga里写axios请求时无法带上参数。
需要如何写?
图片描述

阅读 3.7k
1 个回答

基于 ReduxRedux-Saga 封装的 D.Va 的 Effect 中,返回 Promise 的函数可以直接 yield。如在此例中可写成:

const res = yield api.common.login(defaultState.username, defaultState.password);

所以推测,Redux-Saga 自身应该也是支持的。

不过有个问题是,当前版本的 TypeScript 的 yield 关键词不支持类型推断,在此例中 res 的类型将会是 any。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进