reactjs - runSaga(,secondparam,) 期望哪种类型以及如何制作?
问题描述
我正在尝试编写处理登录的传奇测试。下面是我的代码和我遇到的问题:
const fakeStore = await runSaga(
{
getState: () => ({...state}),
dispatch: (action) => dispatchedActions.push(action)
},
apis.user.login, // this where the issue is from
payload
).done;
Tslint
错误信息:
Argument of type '(user: Authentication) => Promise<IUserResponse>' is not assignable to parameter of type 'Saga1<Authentication>'.
Property 'next' is missing in type 'Promise<IUserResponse>' but required in type 'Iterator<any>'.
这是apis.user
apis{
user: {
login: (user: Authentication):Promise<IUserResponse> =>
axios.post('/api/login', user)
.then((res) => res.data)
.catch((res) => res.data || { message:"" }),
}
}
我不明白如何制作那种Saga1
类型。我查看了类型定义,它是这样的:
export function runSaga<A, S, T1>(
storeInterface: RunSagaOptions<A, S>,
saga: Saga1<T1>,
arg1: T1): Task;
Saga1<T1>
type Saga1<T1> = (arg1: T1) => Iterator<any>;
解决方案
该Saga1
类型指的是生成器函数。这些函数在被调用时会返回一个迭代器,但您不必担心这方面的问题,因为 ReduxSaga 会调用该函数并与迭代器进行交互。您可以runSaga
在我为其他问题创建的这个 CodeSandbox中看到一个使用示例。
推荐阅读
- c++ - c++ Firebase 身份验证错误
- ios - 如何像这样使用 GPUImage 绘制草图边界或铅笔边界?
- css - 使用媒体查询修改 html 标签的字体大小
- python - 在 Linux EC2 实例中使用 sudo pip3 install python-binance 时 python-binance 无法编译错误
- excel - Excel 中 RIGHT 公式的结果不稳定
- jquery - jQuery: if XYZ, add class to this AND next element
- reactjs - enzyme wrappers fail jest equality despite producing identical snapshots
- c++ - 添加一个 op tensorflow 调试
- android - 无法调试 React Native android 应用程序 - 窗口类型 2006 的权限被拒绝
- java - Java:如何获取泛型方法的类型类对象?