我注意到yield call
效果的结果在用作<{p>}时被输入为any
const data = yield call(f);
f
是() => Promise<number>
函数。
我错过了什么或是redux-saga
类型限制吗?
答案 0 :(得分:6)
检查this ongoing thread,tldr;这是一个打字稿限制
答案 1 :(得分:1)
同时,您可以改用以下软件包:typed-redux-saga
之前
import { call, all } from "redux-saga/effects";
...
// Api.fetchUser return User
// but user has type any
const user = yield call(Api.fetchUser, action.payload.userId);
之后
import { call, all } from "typed-redux-saga";
...
// user now has the correct type User
// NOTE: it's yield*, not yield
const user = yield* call(Api.fetchUser, action.payload.userId);