variableDeletions
Reports attempting to delete variables with the delete operator.
✅ This rule is included in the ts untyped
preset.
The delete
operator is only meant to remove properties from objects, not variables.
Attempting to delete a variable in strict mode will cause a syntax error.
In non-strict mode, it will silently fail and return false without actually deleting the variable, which can lead to confusing bugs.
Examples
Section titled “Examples”let count = 5;delete count;
function calculate(value: number) { delete value;}
let count = 5;count = undefined;
const obj = { property: 1 };delete obj.property;
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”This rule should always be enabled, as attempting to delete variables is always incorrect behavior in JavaScript and TypeScript.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Deno:
no-delete-var
- ESLint:
no-delete-var
- Oxlint:
eslint/no-delete-var
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.