@typescript-eslint/typedef 启用呼号

@typescript-eslint/typedef enable call-signature

我最近升级了我的 angular 应用程序以使用 eslint 而不是 tslint。

我现在正在努力启用 call-signature typedef

所以,之前,我有这个:

"typedef": [
    true,
    ...,
    "call-signature"
]

但在 Eslint 中,我找不到等效项。浏览 their git page 时,我看到了这个:

type Options = {
  arrayDestructuring?: boolean;
  arrowParameter?: boolean;
  memberVariableDeclaration?: boolean;
  objectDestructuring?: boolean;
  parameter?: boolean;
  propertyDeclaration?: boolean;
  variableDeclaration?: boolean;
  variableDeclarationIgnoreFunction?: boolean;
};

如何启用呼号?

尽管将所有内容都设置为 true,但这样做不会触发任何警告:

public someMethod() {}

这是我的 tslint 配置:

"@typescript-eslint/typedef": [
    "warn",
    {
        "arrayDestructuring": true,
        "arrowParameter": true,
        "memberVariableDeclaration": true,
        "objectDestructuring": true,
        "parameter": true,
        "propertyDeclaration": true,
        "variableDeclaration": true,
        "variableDeclarationIgnoreFunction": true
    }
]

我尝试添加 call-signature 但没有帮助。

根据文档,您必须使用此规则来强制执行类型定义。

"@typescript-eslint/explicit-function-return-type": [
      "error",
      {
        "allowExpressions": true
      }
    ]

您可以参考这里: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-function-return-type.md

这将在函数、箭头函数和 class 方法上强制执行 TSLint 的相同 return 类型定义规则集。