Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return type of a `yield call`

I've noticed that the result of a yield call effect is typed as any when used as

const data = yield call(f);

while f is a () => Promise<number> function.

Am I missing something or is it a redux-saga typings limitation?

like image 953
zerkms Avatar asked Feb 21 '18 20:02

zerkms


2 Answers

Check this ongoing thread, tldr; it's a typescript limitation

like image 142
Karen Grigoryan Avatar answered Oct 13 '22 15:10

Karen Grigoryan


In the meantime, you can use this package instead: typed-redux-saga

Before

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

After

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);
like image 34
NearHuscarl Avatar answered Oct 13 '22 15:10

NearHuscarl