7

I'm using TypeScript along with TSLint, and I have the following code:

var myObj = {}
var id = "key"
myObj[id] = 1
delete myObj[id]

But I receive a hint from TSLint: Do not delete dynamically computed property keys. (no-dynamic-delete)

The rationale for this rule (as stated on the documentation for TSLint):

Deleting dynamically computed keys is dangerous and not well optimized.


My question is, without disabling this hint in the TSLint configuration file, how should I safely and optimally delete the id key in myObj?

Ari Seyhun
  • 11,506
  • 16
  • 62
  • 109

1 Answers1

5

a) ignore the warning
b) use a Map instead

Bergi
  • 630,263
  • 148
  • 957
  • 1,375