【问题标题】:Eslint arrow function, expected to have type annotationEslint 箭头函数,期望有类型注解
【发布时间】:2020-03-18 15:29:19
【问题描述】:

所以我有以下代码:

public someFunctionName = (someParam: someType): void => {
    ...some code
};

当我在文件上运行 eslint 时,我收到错误:expected someFunctionName to have a type annotation

我能找到解决此问题的唯一方法是删除箭头函数并替换为常规函数。

有谁知道如何解决箭头函数的这个问题?

【问题讨论】:

  • 这是一个类的函数吗?如果有什么特定的原因你想要做一个箭头函数而不是传统的?

标签: angular typescript eslint


【解决方案1】:

类型定义函数签名可能会有所帮助:

type SomeFuncType = (a: number) => void;

const someFunc: SomeFuncType = (a: number): void => {
  //
};

在导出回调类型时也有帮助。

我最近放弃了 tslint 的所有用途,转而采用 typescript-eslint。这包括删除 VS Code tslint 扩展。 更漂亮这些天几乎是我的选择。

【讨论】:

    猜你喜欢
    • 2017-09-13
    • 1970-01-01
    • 2018-08-16
    • 2022-01-08
    • 2016-10-01
    • 1970-01-01
    • 2023-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多