Skip to content

typescript/no-dynamic-delete Restriction

What it does

Disallow using the delete operator on computed key expressions.

Why is this bad?

Deleting dynamically computed keys can be dangerous and in some cases not well optimized. Using the delete operator on keys that aren't runtime constants could be a sign that you're using the wrong data structures. Consider using a Map or Set if you’re using an object as a key-value collection.

Example

ts
const container: { [i: string]: 0 } = {};
delete container["aa" + "b"];

References

Released under the MIT License.