繁体   English   中英

我是否需要在 javascript/typescript 中为匿名函数指定返回类型?

[英]Do I need to specify a return type for an anonymous function in javascript / typescript?

我有以下功能:

    $('td:eq(' + iColumn + ') input', oSettings.oApi._fnGetTrNodes(oSettings))
        .each(function () {
            aData.push(this.value);
         });

在打字稿中,我收到一条消息:

Error   3   Function declared a non-void return type, but has no return expression  

为什么我会收到这条消息? 我可以通过说“return true”来解决该消息。 我应该始终为此指定返回类型吗?

.each()存储库中jquery.d.ts文件中.each()的签名是:

each(func: (index: any, elem: Element) => JQuery);

jQuery 文档说

我们可以通过返回 false 从回调函数中停止循环。

这意味着这个jquery.d.ts是错误的。

如果您从Boris Yankov 的存储库中获取更新版本,它将变为:

each(func: (index: any, elem: Element) => any);

此表格将允许您返回任何东西,或什么都不返回。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM