返回`yield call`的类型

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打字限制?

Kar*_*yan 6

检查这个正在进行的线程,tldr; 这是打字稿限制

  • 也请考虑在此处的链接中包含信息要点。 (2认同)

Nea*_*arl 5

与此同时,您可以使用这个包: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)