@typescript-eslint/no-array-delete

Disallow delete on an element of an array

has suggestionsneeds types

Also called typescript-eslint/no-array-delete, typescript/no-array-delete

delete items[1] doesn't remove the element. It leaves a hole, so the array keeps its length and items[1] reads as undefined. To take the element out and close the gap, use splice.

The report comes with a suggestion that rewrites the delete as a splice call. That moves the later items, so only --fix-dangerously applies it, not --fix-suggestions.

bun lint --type-aware turns this rule on in TypeScript files.

Configure#

Off by default. This rule needs types, so turning it on makes bun lint type check your code first.

bunfig.toml
[lint.rules]
"@typescript-eslint/no-array-delete" = "error" # or "warn"

Examples#

example.ts1 problem
const items = ["a", "b", "c"];

delete items[1]; // ["a", <empty>, "c"], length 3
example.tsNo problems
const items = ["a", "b", "c"];

items.splice(1, 1); // ["a", "c"], length 2

const scores: Record<string, number> = { ada: 1 };
delete scores["ada"];