gpt4 book ai didi

javascript - 返回 promise 在 TypeScript 中给出 "Supplied parameters do not match"

转载 作者:行者123 更新时间:2023-12-03 12:22:43 25 4
gpt4 key购买 nike

我正在转换 jQuery 插件以使用 promises而不是callbacks 。这应该是非常基本的,但不确定问题是否出在我链接 Promise 的方法、我的返回类型,或者 TypeScript 只是过于挑剔。

我不断收到此错误:

Error   27  Supplied parameters do not match any signature of call target:
Type '(value: {}) => {}' requires a call signature, but type 'JQueryPromise<any>' lacks one.

我的函数的简化版本如下所示:

    _navigate(forward: boolean, $panel: JQuery, target: string): JQueryPromise<any>
{
var dfd = $.Deferred();
switch (target)
{
// '_self' is a full page load link
case '_self':
setTimeout(function ()
{
window.location.href = url;
}, 0);

// Return empty promise - as we are about to lose the page
dfd.resolve(true);
break;
// _back re-displays a panel already loaded
case '_back':
// Fetch a reference to the panel before this one
var $existingPanel = THIS._getNextPanel($panel, false);

// >>>> ERROR ON NEXT LINE <<<<<<
// This will animate back in the previous panel - promise on complete
dfd = dfd.then(THIS._gotoPanel($existingPanel, false, true, target));

break;
// [SNIP]
}
return dfd.promise();
}

_gotoPanel 只是另一种方法,它也返回 JQueryPromise<any> promise :

    _gotoPanel($panel: JQuery, forward: boolean, transition: boolean, target?: string): JQueryPromise<any>

最终版本需要能够链接方法和 $.ajax 中任意数量的 promise 。打电话,但我一直遇到这个错误。如果不是 JQueryPromise<any> 我的返回类型应该是什么样子?

最佳答案

What should my return type look like if not JQueryPromise<any>?

作为错误消息'(value: {}) => {}' requires a call signature说,您需要将回调传递给 .then() ,而不是 promise !

我想你只是想要

dfd = THIS._gotoPanel($existingPanel, false, true, target);

作为dfd否则将根本无法在 _back 中得到解决案例。

关于javascript - 返回 promise 在 TypeScript 中给出 "Supplied parameters do not match",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24362341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com