如何修复"TS2769:此呼叫无过载" [英] How to repair a 'TS2769: No overload matches this call'
问题描述
软件包更新后,我突然收到奇怪的打字稿错误:
After package updates, I suddenly get weird typescript errors:
[tsl] C:.. \ UI \ src \ sagas.ts中的错误(40,21) TS2769:没有过载与该呼叫匹配.
最后一次重载给出了以下错误.无法将类型"LOAD_IDS"的参数分配给类型"TakeableChannel"的参数.
The last overload gave the following error. Argument of type '"LOAD_IDS"' is not assignable to parameter of type 'TakeableChannel'.
sagas.ts 的相应行39-41是
The corresponding lines 39-41 of sagas.ts
are
function* watchIds() {
yield takeEvery(Actions.LOAD_IDS, loadIds);
}
函数 function * loadIds({forceReload})
是在同一 sagas.ts
中定义的,只是在API调用中定义的.
The function function* loadIds({ forceReload })
is defined in the same sagas.ts
and just the API call.
TS错误是什么意思,我该如何解决?
-
我的
packages.json
看起来像这样: https://pastebin.com/raw/nJ0cPNXb
也许也很重要:我的 webpack.config.js
是 https://pastebin.com/raw/JNdXTCMb
Maybe also important: My webpack.config.js
is https://pastebin.com/raw/JNdXTCMb
参考文献
- 没有重载匹配这个电话.不能将字符串"类型分配给信号"类型
- https://engineering.datorama.com/demystifying-function-Type-eb9f8ca6b87d超载
- 排除相应的动作,例如原始
import
语句中的takeEvery
. - 使用
作为Eff
导入所有操作,其中Eff
是别名. - 定义一个与原始动作同名的新常量.
- Exclude the corresponding action, e.g.
takeEvery
from the originalimport
statement. - Import all action with
as Eff
whereEff
is an alias. - Define a new constant with the same name as the original action.
推荐答案
我的同事最终教我了一种解决方法:
My colleague eventually taught me a workaround:
import { put, fork, select, call } from 'redux-saga/effects' // <-- modified
import * as Eff from 'redux-saga/effects' // <-- new
// ...
const takeEvery: any = Eff.takeEvery; // <-- new
const takeLatest: any = Eff.takeLatest; // <-- new
据我了解,他的想法是明确允许任何
类型.
As far as I understand him, the idea is to explicity allow any
type.
我知道Facebook(作为React的开发者)确实明确声明不应不使用继承,请参见
I am aware that Facebook (as developer of React) does explicitly state that one should not use inheritance, see https://reactjs.org/docs/composition-vs-inheritance.html
这篇关于如何修复"TS2769:此呼叫无过载"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!