Skip to content

dynamicDeletes

Disallow using the delete operator on computed key expressions.

✅ This rule is included in the ts logical preset.

Deleting dynamically computed keys can be dangerous and is often not well optimized. Using the delete operator on keys that aren’t runtime constants could be a sign you’re using the wrong data structures.

Consider using a Map or Set if you’re using an object as a key-value collection. Dynamically adding and removing keys from objects can cause edge case bugs related to hidden properties and non-configurable properties.

const key = "property";
delete obj[key];
delete obj[getKey()];
const i = 0;
delete arr[i];

This rule is not configurable.

When you know your keys are safe to delete and you’ve considered the performance and safety implications, you may disable this rule for those specific situations.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.