【问题标题】:What does it mean when TsLint says "expected callSignature to have a typedef."当 TsLint 说“预期 callSignature 有一个 typedef”是什么意思。
【发布时间】:2014-10-17 00:33:21
【问题描述】:

我的代码中有一个函数:

networkStop = (action: string = null) => {
    this.action[action] = false;
    this.net = false;
    this.netd = false;
}

我收到一个 TsLint 错误提示:

Message 4   TsLint: expected callSignature to have a typedef.

谁能解释一下这是什么意思?

【问题讨论】:

    标签: typescript signature tslint


    【解决方案1】:

    “缺少类型定义”有关详细信息,请参阅:https://github.com/palantir/tslint/blob/master/src/rules/typedefRule.ts。基本上 some 注释(用于函数,因为callSignature)丢失。

    可能是修复(明确指定返回类型):

    networkStop = (action: string = null):void => {
        this.action[action] = false;
        this.net = false;
        this.netd = false;
    }
    

    【讨论】:

    • 你能告诉我在 () 后面加上 :any 和 void 一样吗?在此示例中,它什么也不返回,那么我该如何指定呢?谢谢
    • 不一样。但是anyvoid 兼容,即any 可以接受anything 甚至void。在这种情况下我会使用void ;)
    • 对于 void 我应该输入 :void 而不是 :any 还是有特殊的语法?
    • 对我很有用
    • 如何将它用于 getter 函数?
    【解决方案2】:

    为了避免构建错误。 在 tslint.json 文件中编写如下代码:-

    "typedef": [
      false,
      "call-signature"
    ],
    

    tslint.json 中的这行代码并没有使方法的返回类型成为必需的。

    【讨论】:

    • 这不是这个问题的答案
    猜你喜欢
    • 2014-01-24
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    • 2023-03-10
    • 1970-01-01
    相关资源
    最近更新 更多