Disallow using the delete operator on computed key expressions.
This rule applies only to .js and .ts files.
// code-linter.json5
{
"rules": {
"@typescript-eslint/no-dynamic-delete": "error"
}
} 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']; 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()]; plugin:@typescript-eslint/recommended plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.