Skip to main content

strict-array-methods

Requires boolean return types on the following array method functions:

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.

Resources