Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

no-array-delete

Disallow using thedelete operator on array values.

💡

Some problems reported by this rule are manually fixable by editorsuggestions.

💭

This rule requirestype information to run, which comes with performance tradeoffs.

When using thedelete operator with an array value, the array'slength property is not affected,but the element at the specified index is removed and leaves an empty slot in the array.This is likely to lead to unexpected behavior. As mentioned in theMDN documentation,the recommended way to remove an element from an array is by using theArray#splice method.

  • Flat Config
  • Legacy Config
eslint.config.mjs
exportdefault tseslint.config({
rules:{
"@typescript-eslint/no-array-delete":"error"
}
});

Try this rule in the playground ↗

Examples

  • ❌ Incorrect
  • ✅ Correct
declareconst arr:number[];

delete arr[0];
Open in Playground

Options

This rule is not configurable.

When Not To Use It

When you want to allow the delete operator with array expressions.


Type checked lint rules are more powerful than traditional lint rules, but also require configuringtype checked linting.

SeeTroubleshooting > Linting with Type Information > Performance if you experience performance degradations after enabling type checked rules.

Resources


[8]ページ先頭

©2009-2025 Movatter.jp