menu
no-array-fill-with-reference-type
Disallow Array.fill values that share mutable references
Array.fill places the same managed reference in every selected element, so later mutation is shared by all of them.
Instead, you SHOULD construct each mutable value independently with Array.from or an explicit loop.
Reported
1class Cell {2 value: int32 = 0;3}4 5function cells(): Cell[] {6 const values = [new Cell(), new Cell(), new Cell()];7 values.fill(new Cell());8 return values;9}Accepted
1class Cell {2 value: int32 = 0;3}4 5function cells(): Cell[] {6 return [new Cell(), new Cell(), new Cell()];7}