Skip to content

arrayEmptyCallbackSlots

Reports array methods with callbacks that will never be invoked on arrays with empty slots.

✅ This rule is included in the ts logical presets.

When the Array constructor is called with a single number argument, it creates an array with the specified number of empty slots (not actual undefined values). Callback methods like map, filter, forEach, and others skip empty slots, so callbacks passed to these methods will never be invoked.

This rule reports when array methods with callbacks are called on arrays created with new Array(n).

new Array(5).map((_) => 0);
new Array(10).filter((value) => value > 0);
new Array(3).forEach((item) => console.log(item));
new Array(5).every((value) => value !== undefined);

This rule is not configurable.

If you intentionally use new Array(n) for its other properties (like setting length) and understand that callbacks won’t be invoked, you can disable this rule. However, this pattern is rarely intentional and usually indicates a bug.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.