{"record":{"id":"0de5e976163cd048","repo":"oxc-project/oxc","slug":"do-not-delete-dynamically-computed-property-keys","errorCode":null,"errorMessage":"Do not delete dynamically computed property keys.","messagePattern":"Do not delete dynamically computed property keys\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/no_dynamic_delete.rs","lineNumber":44,"sourceCode":"    /// ```ts\n    /// const container: { [i: string]: 0 } = {};\n    /// delete container['aa' + 'b'];\n    /// ```\n    ///\n    /// Examples of **correct** code for this rule:\n    /// ```ts\n    /// const container: { [i: string]: 0 } = {};\n    /// delete container.aab;\n    /// ```\n    NoDynamicDelete,\n    typescript,\n    restriction,\n    version = \"0.5.2\",\n    short_description = \"Disallow using the delete operator on computed key expressions.\",\n);\n\nfn no_dynamic_delete_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not delete dynamically computed property keys.\")\n        .with_help(\"Use a static property key, or use a Map/Set for dynamic keys.\")\n        .with_note(\n            \"Frequent property deletions can move objects to slower dictionary-mode properties and hurt inline-cache optimizations. See: https://v8.dev/blog/fast-properties.\",\n        )\n        .with_label(span)\n}\n\nimpl Rule for NoDynamicDelete {\n    fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {\n        let AstKind::UnaryExpression(expr) = node.kind() else { return };\n        if !matches!(expr.operator, UnaryOperator::Delete) {\n            return;\n        }\n\n        let Expression::ComputedMemberExpression(computed_expr) = &expr.argument else { return };\n        let inner_expression = computed_expr.expression.get_inner_expression();\n        if inner_expression.is_string_literal() || inner_expression.is_number_literal() {\n            return;","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/no_dynamic_delete.rs#L26-L62","documentation":"typescript/no-dynamic-delete reports `delete obj[computedKey]` — the delete operator applied to a computed member expression. The rule's note cites V8 behavior: frequent deletions can push objects into dictionary-mode (slow) properties and hurt inline caches. Help text suggests a static key or a Map/Set for dynamic keys.","triggerScenarios":"Any UnaryExpression with operator `delete` whose argument is a computed member access: `delete cache[key]`, `delete obj[propName]`, `delete map[`${a}-${b}`]`; deleting a static property (`delete obj.key`) is not reported.","commonSituations":"Hand-rolled caches or registries using plain objects with variable keys; porting Map-like logic from objects; memoization tables that grow and shrink; config maps where entries are removed at runtime.","solutions":["Use a Map and `cache.delete(key)` — designed for dynamic keys","Use a Set for presence tracking: `set.delete(key)`","If the key set is known, switch to static deletion: `delete obj.fixedKey`","If object shape must be preserved, set to undefined instead of deleting: `obj[key] = undefined` (note: shape stays fast but the key remains)"],"exampleFix":"// before\nconst cache: Record<string, Data> = {};\ndelete cache[key];\n\n// after\nconst cache = new Map<string, Data>();\ncache.delete(key);","handlingStrategy":"fallback","validationCode":"// .oxlintrc.json\n{\n  \"rules\": { \"typescript/no-dynamic-delete\": \"warn\" }\n}\n\n// quick audit for the pattern before adopting the rule:\n// rg --type ts \"delete\\s+\\w+\\[\" src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Model dynamic-key stores with Map/Set from the start; their delete() is designed for it","Avoid delete on hot-path objects in performance-sensitive code (V8 dictionary-mode transition)","When shape stability matters more than removal, assign undefined instead of deleting"],"tags":["typescript","lint","delete-operator","performance","oxlint"],"backgroundTag":"dynamic-delete-computed-key","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}