目录

@typescript-eslint/no-dynamic-delete

Disallow using the delete operator on computed key expressions.

This rule applies only to .js and .ts files.

Rule Configuration

// code-linter.json5
{
  "rules": {
    "@typescript-eslint/no-dynamic-delete": "error"
  }
}

Options

This rule is not configurable.

Example of Correct Code

const container: Record<string, number> = {
  /* ... */
};

// Constant runtime lookups by string index
delete container.aaa;

// Constants that must be accessed by []
delete container['7'];
// '-Infinity' is number.  
delete container['-Infinity'];

Example of Incorrect Code

const container: Record<string, number> = {
  /* ... */
};

// Can be replaced with the constant equivalents, such as container.aaa
delete container['aaa'];
// 'Infinity' may be a string constant
delete container['Infinity'];

// Dynamic, difficult-to-reason-about lookups
const name = 'name';
delete container[name];
delete container[name.toUpperCase()];

Rule Set

plugin:@typescript-eslint/recommended
plugin:@typescript-eslint/all

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