admin管理员组文章数量:1429538
Problem Statement:
I'm unable to specify type for the yield call()
. The yield is calling an API that fetches some data from server. The of data type is ServerResponse. What I want to do is specify type as follows:
const response: ServerResponse = yield serverCall();
But I Typescript throws this error: Redux Saga: Type 'unknown' is not assignable to type 'ServerResponse'
.
Code:
function* serverSaga(): Generator {
try {
// TS throws error here;
const response: ServerResponse = yield serverCall();
...
...
} catch (err) {
...
}
}
const serverCall = async (): Promise<ServerResponse> => {
try {
const response = await ...
return response;
} catch (err) {
...
}
};
Problem Statement:
I'm unable to specify type for the yield call()
. The yield is calling an API that fetches some data from server. The of data type is ServerResponse. What I want to do is specify type as follows:
const response: ServerResponse = yield serverCall();
But I Typescript throws this error: Redux Saga: Type 'unknown' is not assignable to type 'ServerResponse'
.
Code:
function* serverSaga(): Generator {
try {
// TS throws error here;
const response: ServerResponse = yield serverCall();
...
...
} catch (err) {
...
}
}
const serverCall = async (): Promise<ServerResponse> => {
try {
const response = await ...
return response;
} catch (err) {
...
}
};
Share
Improve this question
asked Jul 13, 2020 at 15:27
Vinay SharmaVinay Sharma
3,8176 gold badges38 silver badges69 bronze badges
4
-
Generator
is a generic. You should be writing something likeserverSage(): Generator<some, cool, types>{}
. I forget which parameter is which. – zero298 Commented Jul 13, 2020 at 15:32 -
@zero298 would great if you can let me know about params
本文标签: javascriptRedux Saga Type 39unknown39 is not assignable to type 39ServerResponse39Stack Overflow
版权声明:本文标题:javascript - Redux Saga: Type 'unknown' is not assignable to type 'ServerResponse' - Stack Overf 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745452434a2658949.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论