目录

@typescript-eslint/prefer-includes

Enforce the includes method over the indexOf method.

Rule Configuration

// code-linter.json5
{
  "rules": {
    "@typescript-eslint/prefer-includes": "error"
  }
}

Options

This rule is not configurable.

Example of Correct Code

const str: string = 'hello';
const array: string[] = ['hello'];
const readonlyArray: readonly string[] = ['hello'];

str.includes('h');
array.includes('h');
readonlyArray.includes('h');

Example of Incorrect Code

const str: string = 'hello';
const array: string[] = ['hello'];
const readonlyArray: readonly string[] = ['hello'];

const num = -1;
let vv = str.indexOf('h') !== num;
vv = vv && array.indexOf('h') !== num;
vv = vv && readonlyArray.indexOf('h') !== num;
export { vv };

Rule Set

plugin:@typescript-eslint/all

For details about how to configure Code Linter check rules, see Code Linter.