Skip to content

deletes

Reports using the delete operator.

✅ This rule is included in the performance logical presets.

The delete operator in JavaScript modifies the shape of objects, which prevents modern JavaScript engines from optimizing their internal representations. When you delete a property, the engine can no longer use fast property access paths that were optimized for that object’s original shape.

These deoptimizations can significantly impact performance in performance-critical code paths, especially when objects are created and modified frequently.

const
const user: {
name: string;
age: number;
email: string;
}
user
= {
name: string
name
: "Alice",
age: number
age
: 30,
email: string
email
: "alice@example.com" };
delete
const user: {
name: string;
age: number;
email: string;
}
user
.
email: string
email
;
function
function clearCache(cache: Record<string, any>): void
clearCache
(
cache: Record<string, any>
cache
:
type Record<K extends keyof any, T> = { [P in K]: T; }

Construct a type with a set of properties K of type T

Record
<string, any>) {
for (const
const key: string
key
in
cache: Record<string, any>
cache
) {
delete
cache: Record<string, any>
cache
[
const key: string
key
];
}
}

This rule is not configurable.

If you are not concerned about performance in a particular code path, or if you need the precise semantics of the delete operator (such as affecting property enumeration or reflecting in hasOwnProperty), you may wish to disable this rule.

In some cases, the performance impact is negligible and code clarity may be more important than the optimization.

Made with ❤️‍🔥 around the world by the Flint team and contributors.