# prefer-includes

Rule `typescript/prefer-includes`. Enforce `includes` method over `indexOf` method

- Source: typescript
- Technologies: TypeScript
- Kind: suspicious
- Needs type information: yes
- Autofix: yes, in at least one linter
- Reach: 2.6M weekly downloads of presets that enable it
- Trend: +92.2% last quarter
- Rank: #1472 by reach, #282 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `@typescript-eslint/prefer-includes` | no | safe | package `@typescript-eslint/eslint-plugin` | [docs](https://typescript-eslint.io/rules/prefer-includes) |
| Oxlint | `typescript/prefer-includes` | no | safe | plugin `typescript`, category pedantic | [docs](https://oxc.rs/docs/guide/usage/linter/rules/typescript/prefer-includes.html) |
| Biome | `nursery/useIncludes` | no | unsafe | group nursery, since 2.5.0 | [docs](https://biomejs.dev/linter/rules/use-includes/) |

## Code examples

### Incorrect: the rule reports this

```ts
const str: string;
const array: any[];
const readonlyArray: ReadonlyArray<any>;
const typedArray: UInt8Array;
const maybe: string;
const userDefined: {
  indexOf(x: any): number;
  includes(x: any): boolean;
};

str.indexOf(value) !== -1;
array.indexOf(value) !== -1;
readonlyArray.indexOf(value) === -1;
typedArray.indexOf(value) > -1;
maybe?.indexOf('') !== -1;
userDefined.indexOf(value) >= 0;

/example/.test(str);
```

### Correct: the rule accepts this

```ts
const str: string;
const array: any[];
const readonlyArray: ReadonlyArray<any>;
const typedArray: UInt8Array;
const maybe: string;
const userDefined: {
  indexOf(x: any): number;
  includes(x: any): boolean;
};

str.includes(value);
array.includes(value);
!readonlyArray.includes(value);
typedArray.includes(value);
maybe?.includes('');
userDefined.includes(value);

str.includes('example');

// The two methods have different parameters.
declare const mismatchExample: {
  indexOf(x: unknown, fromIndex?: number): number;
  includes(x: unknown): boolean;
};
mismatchExample.indexOf(value) >= 0;
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import tseslint from "typescript-eslint";

export default [
  {
    plugins: { "@typescript-eslint": tseslint.plugin },
    rules: {
      "@typescript-eslint/prefer-includes": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "typescript/prefer-includes": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "useIncludes": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |

## Related rules

- [unicorn/prefer-includes](https://lintradar.dev/rules/unicorn/prefer-includes.md): Prefer `.includes()` over `.indexOf()`, `.lastIndexOf()`, and `Array#some()` when checking for existence or non-existence.
- [typescript/no-unnecessary-qualifier](https://lintradar.dev/rules/typescript/no-unnecessary-qualifier.md): Disallow unnecessary namespace qualifiers
- [typescript/prefer-nullish-coalescing](https://lintradar.dev/rules/typescript/prefer-nullish-coalescing.md): Enforce using the nullish coalescing operator instead of logical assignments or chaining
- [typescript/strict-boolean-expressions](https://lintradar.dev/rules/typescript/strict-boolean-expressions.md): Disallow certain types in boolean expressions
- [typescript/prefer-readonly](https://lintradar.dev/rules/typescript/prefer-readonly.md): Require private members to be marked as `readonly` if they're never modified outside of the constructor
- [typescript/prefer-find](https://lintradar.dev/rules/typescript/prefer-find.md): Enforce the use of Array.prototype.find() over Array.prototype.filter() followed by [0] when looking for a single result

---

Web page: https://lintradar.dev/rules/typescript/prefer-includes. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
