返回`yield call`的类型

时间:2018-02-21 20:08:26

标签: typescript redux-saga

我注意到yield call效果的结果在用作<{p>}时被输入为any

const data = yield call(f);

f() => Promise<number>函数。

我错过了什么或是redux-saga类型限制吗?

2 个答案:

答案 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);