【问题标题】:Avoiding general Function type in react + typescript在 react + typescript 中避免通用函数类型
【发布时间】:2020-09-15 17:41:24
【问题描述】:

我正在寻找一个规则来阻止将“函数”用作类型

myMethod: Function;

我没有找到任何东西,所以我愿意接受建议:)

【问题讨论】:

  • 你确定是打字稿吗?据我所知,TS 没有任何本机泛型函数类型。但是,Flow 确实如此。

标签: reactjs typescript eslint


【解决方案1】:

您可以使用@typescript-eslint/ban-types 规则Rule Link。但这也会禁止其他默认类型,例如 StringBoolean 等。Link of other default banned types

如果您只想禁止 Function 并禁用其他禁令,请将其添加到您的 .eslintrc 文件中。

"@typescript-eslint/ban-types": ["error",
    {
        "types": {
            "String": false,
            "Boolean": false,
            "Number": false,
            "Symbol": false,
            "{}": false,
            "Object": false,
            "object": false,
            "Function": true,
        },
        "extendDefaults": true
    }
]

【讨论】:

    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 2019-03-19
      • 2022-11-24
      • 2021-06-11
      • 2021-12-08
      • 2018-12-31
      • 1970-01-01
      • 1970-01-01
      • 2019-06-04
      • 1970-01-01
      相关资源
      最近更新 更多