我想传递action.url字符串作为返回Promise的topicDummy函数的参数,但它一直显示我
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`);
}
}
2条答案
按热度按时间e7arh2l61#
How to repair a 'TS2769: No overload matches this call'可能是相关的,
它建议,而不是
以便使用
也可以看看https://github.com/redux-saga/redux-saga/issues/2018
您还需要在某个点上解决该承诺,并且如果要使用这些数据,您需要“* 返回 *”这些数据。
所以改变
至
w7t8yxp52#
我想我也遇到了同样的问题,我在我的案例中找到了解决办法。
我有这样的代码:
我在
createProgramDashboard
下看到一条红色的弯曲线,并显示以下错误:结果是,我发送的第一个参数
programId
是number
,而createProgramDashboard
期望的是string
。显然,当发送给
call
函数的一些参数的类型(在我的例子中为programId: number
)与被调用的函数(在我的例子中为createProgramDashboard
)所期望的参数的类型(在我的例子中为programId: string
)不匹配时,就会显示此错误。因此,这修复了错误: