Skip to content

dynamicDeletes

Disallow using the delete operator on computed key expressions.

✅ This rule is included in the ts logical and logicalStrict presets.

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.

AEconsB0kAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dproper1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">72dele53 obj[key<];d ivclassNa="meco"><];d>72dele53 obB0getK53()<];d ivclassNa="meco"><];d>AEconsB<0isp ansty="le--0:#C792EA;--1:#8844">AE <= sp ansty="le--0:#F78C6C;--1:#AA09">8<20sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">72dele53 arr[i<];d ivclassNa="meco"><];d>
6E72de3F53< obj spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72prop3<;di vdivclass="Nameexpressive-">6E72de3F53 1<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dlit1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53] ;divclass="Name"><;di vdivclass="Nameexpressive-">6E72de3F53 0<9820 spans="tyle--0:#D6DEEB;--1:#40">3F<53] ;divclass="Name"><[0]><;di vdivclass="Nameexpressive-">44AEco61B<0map spans="tyle--0:#C792EA;--1:#88">44A6E7<2new spans="tyle--0:#C792EA;--1:#88">4<4AE spans="tyle--0:#82AAFF;--1:#3B">61B<0Map spans="tyle--0:#C792EA;--1:#88">4<4AE< spans="tyle--0:#C5E478;--1:#3B">61B0st4461B0nu4<4AE> spans="tyle--0:#D6DEEB;--1:#40">3F5><3() ;divclass="Nameec-">3F5<3map spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0de31<111" spans="tyle--0:#ECC48D;--1:#98">4E41<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name">

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.