我想将action.url字符串作为topicDummy函数的参数传递,该函数返回Promise, 却不断向我展示
No overload matches this call.
The last overload gave the following error.
Argument of type '<TopicData>(url: string) => Promise<TopicData>' is not assignable to parameter of type '{ context: unknown; fn: (this: unknown, ...args: any[]) => any; }'.
Type '<TopicData>(url: string) => Promise<TopicData>' is missing the following properties from type '{ context: unknown; fn: (this: unknown, ...args: any[]) => any; }': context, fnts(2769)
effects.d.ts(499, 17): The last overload is declared here.
这些是我的全部代码。
export type TopicData = {
name: TopicName
data: CardData[]
}
const dummyTopicData: TopicData = Object.assign({
topic: 'etc',
data: dummyData()
}, )
function topicDummy<TopicData>(url: string): Promise<TopicData> {
return new Promise((resolve, reject) => {
setTimeout(() =>
dummyTopicData
, 700);
})
}
function* fetchTopic(action: DispatchAction){
try{
yield put(topicCreator.load());
const topicList = yield call(topicDummy, action.url); // <- complain here.
yield put(topicCreator.success(topicList));
} catch(error){
throw new Error(`Error exist in fetchTopic function`);
}
}
答案 0 :(得分:2)
How to repair a 'TS2769: No overload matches this call'可能是相关的,
建议使用
代替import {call} from "redux-saga/effects";
使用
import * as Effects from "redux-saga/effects";
const call: any = Effects.call;
还可以看看https://github.com/redux-saga/redux-saga/issues/2018
您还需要一次解决承诺,如果要使用它们,则需要“ 返回”数据。
所以改变
return new Promise((resolve, reject) => {
setTimeout(() =>
dummyTopicData
, 700);
})
到
return new Promise((resolve, reject) => {
setTimeout(() =>
resolve(dummyTopicData)
, 700);
})