無効にする方法 _@TypeScript-eslint/explicit-function-return-type
_ for some()
、filter()
、forEach()
?
毎回some()
およびfilter()
のboolean
戻り値型を宣言し、forEach()
のvoid
を宣言するのは非常に面倒です。
_[2, 5, 8, 1, 4].some(elem => elem > 10)
_
_[2, 5, 8, 1, 4].some((elem):boolean => elem > 10)
_
このルールでエラーが発生することなく、最初のパターン(「無効」とマークされている)を使用できるようにしたいと思います。
あなたの.eslintrc
ファイルrules
の下に以下を追加できます:
{
...
"plugins": ["@TypeScript-eslint"],
"rules": {
...
"@TypeScript-eslint/explicit-function-return-type": {
"allowExpressions": true
}
}
}
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
}
]
}
}
]
}
{allowExpressions:true}を使用したこのルールの正しいコードの例:
node.addEventListener('click', () => {});
node.addEventListener('click', function() {});
const foo = arr.map(i => i * i);
詳細は allowExpressions のドキュメントを参照してください。