Skip to content

arrayIncludesMethods

Reports using Array#some() with simple equality checks that can be replaced with .includes().

✅ This rule is included in the ts stylistic and stylisticStrict presets.

Array.prototype.some() is intended for more complex predicate checks. When the callback only performs a simple equality check (x === value or x == value), .includes() is more readable and expressive.

This rule reports when .some() can be simplified to .includes().

declare const
const array: string[]
array
: string[];
const array: string[]
array
.
Array<string>.some(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean

Determines whether the specified callback function returns true for any element of an array.

@parampredicate A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.

@paramthisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

some
((
item: string
item
) =>
item: string
item
=== "value");
declare const
const array: string[]
array
: string[];
const array: string[]
array
.
Array<string>.some(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean

Determines whether the specified callback function returns true for any element of an array.

@parampredicate A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.

@paramthisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

some
((
item: string
item
) => "value" ===
item: string
item
);
declare const
const array: number[]
array
: number[];
declare const
const target: number
target
: number;
const array: number[]
array
.
Array<number>.some(predicate: (value: number, index: number, array: number[]) => unknown, thisArg?: any): boolean

Determines whether the specified callback function returns true for any element of an array.

@parampredicate A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.

@paramthisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

some
((
element: number
element
) =>
element: number
element
===
const target: number
target
);
declare const
const array: string[]
array
: string[];
const array: string[]
array
.
Array<string>.some(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean

Determines whether the specified callback function returns true for any element of an array.

@parampredicate A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.

@paramthisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

some
(function (
item: string
item
) {
return
item: string
item
=== "value";
});

This rule is not configurable.

If your codebase uses .some() for consistency even with simple equality checks, or if you have a large number of existing uses that would be difficult to refactor, you might prefer to disable this rule.

Made with ❤️‍🔥 around the world by the Flint team and contributors.