Grz*_*rzg 20 typescript eslint
如何禁用@typescript-eslint/explicit-function-return-type为some(),filter(),forEach()?
每次都boolean为some()andfilter()和voidfor声明一个返回类型是很烦人的forEach()。
[2, 5, 8, 1, 4].some(elem => elem > 10)
Run Code Online (Sandbox Code Playgroud)
[2, 5, 8, 1, 4].some((elem):boolean => elem > 10)
Run Code Online (Sandbox Code Playgroud)
我希望能够使用第一个模式(标记为“无效”)而不会从此规则中出错。
Pat*_*rts 23
在您的.eslintrc文件中,您可以添加以下内容rules:
{
...
"plugins": ["@typescript-eslint"],
"rules": {
...
"@typescript-eslint/explicit-function-return-type": {
"allowExpressions": true
}
}
}
Run Code Online (Sandbox Code Playgroud)
根据关于allowExpressions的文档,这将允许您向任何函数提供内联回调,而无需声明显式返回类型。
这是.eslintrc应该如何配置规则@typescript-eslint/explicit-function-return-type
{
"@typescript-eslint/explicit-function-return-type": "off",
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"parser": "@typescript-eslint/parser",
...
"rules": {
...
"@typescript-eslint/explicit-function-return-type": [
"error",
{
"allowExpressions": true
}
]
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
此规则的正确代码示例为 { allowExpressions: true }:
node.addEventListener('click', () => {});
node.addEventListener('click', function() {});
const foo = arr.map(i => i * i);
Run Code Online (Sandbox Code Playgroud)
更多信息请参阅allowExpressions 的文档。
| 归档时间: |
|
| 查看次数: |
16478 次 |
| 最近记录: |