arrayIncludesMethods
Reports using
Array#some()with simple equality checks that can be replaced with.includes().
✅ This rule is included in the ts stylistic 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().
Examples
Section titled “Examples”declare const array: string[];array.some((item) => item === "value");declare const array: string[];array.some((item) => "value" === item);declare const array: number[];declare const target: number;array.some((element) => element === target);declare const array: string[];array.some(function (item) { return item === "value";});declare const array: string[];array.includes("value");declare const array: string[];array.some((item) => item.startsWith("v"));declare const array: number[];array.some((item) => item > 0);declare const array: object[];array.some((item) => item.id === 1);Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
unicorn/prefer-includes
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.