zer*_*kms 6 typescript redux-saga
我注意到yield call效果的结果是any在用作时输入的
const data = yield call(f);
Run Code Online (Sandbox Code Playgroud)
虽然f是一个() => Promise<number>功能.
我错过了什么或是否是一种redux-saga打字限制?
与此同时,您可以使用这个包: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);
Run Code Online (Sandbox Code Playgroud)
后
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1545 次 |
| 最近记录: |