当TsLint说"预期callSignature有一个typedef"时,它意味着什么.

29 typescript

我的代码中有一个函数:

networkStop = (action: string = null) => {
    this.action[action] = false;
    this.net = false;
    this.netd = false;
}
Run Code Online (Sandbox Code Playgroud)

我收到一个TsLint错误说:

Message 4   TsLint: expected callSignature to have a typedef.
Run Code Online (Sandbox Code Playgroud)

有人可以解释这意味着什么吗?

bas*_*rat 27

"缺少类型定义"请参阅:https://github.com/palantir/tslint/blob/master/src/rules/typedefRule.ts以获取详细信息.基本上缺少一些注释(对于函数因为callSignature).

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

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

  • 不是不一样的.但是`any`与`void`是兼容的,即`any`可以带*任何*甚至`void`.在这种情况下我会使用`void`;) (2认同)

Sha*_*dit 19

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

"typedef": [
  false,
  "call-signature"
],
Run Code Online (Sandbox Code Playgroud)

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

  • 这不是这个问题的答案 (3认同)