strict-array-methods
💼 This rule is enabled in the ✅ recommended
config.
Requires boolean return types on some specific array methods.
💠This rule requires type information.
Rule Details​
This rule targets the following Array methods:
Array.prototype.every
Array.prototype.filter
Array.prototype.find
Array.prototype.findIndex
Array.prototype.findLast
Array.prototype.findLastIndex
Array.prototype.some
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​
This rule is not configurable.