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).
Examples
Section titled “Examples”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);new Array(5).fill(0).map((_) => 1);Array.from({ length: 5 }, (_, index) => index);new Array(5).fill(undefined).forEach((item) => console.log(item));[1, 2, 3].map((value) => value * 2);Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Oxlint:
oxc/uninvoked-array-callback
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.