避免在react + typescript中使用通用函数类型

son*_*nsi 3 typescript reactjs eslint

我正在寻找一条规则来阻止使用“函数”作为类型

myMethod: Function;

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

jon*_*ode 7

您可以使用@typescript-eslint/ban-types规则规则链接。但这也会禁止其他默认类型String,例如Boolean、 等。其他默认禁止类型的链接

如果您只想禁止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
    }
]
Run Code Online (Sandbox Code Playgroud)