strict-array-methods
Requires boolean return types on the following array method functions:
Array.prototype.every
Array.prototype.filter
Array.prototype.find
Array.prototype.findIndex
Array.prototype.findLast
Array.prototype.findLastIndex
Array.prototype.some
Rule Details
Normally, the @typescript-eslint/strict-boolean-expressions
ESLint rule catches bugs where you are supposed to put a boolean value but accidentally put something else. Unfortunately, that rule does not catch this mistake when using array methods.
Thus, an additional ESLint rule is necessary to handle this.
// Bad
const numbers: number[] = [];
const filteredNumbers = numbers.filter((element) => {
return element;
});
// Good
const numbers: number[] = [];
const filteredNumbers = numbers.filter((element) => {
return element !== 0;
});
Options and Defaults
{
"rules": {
"complete/strict-array-methods": "error"
}
}
This rule is not configurable.