sindresorhus/eslint-plugin-unicorn

`no-useless-spread` it is not safe to remove spread in `[...foo.concat(bar)]`

Chiusa

#2480 aperta il 16 ott 2024

 (4 commenti) (0 reazioni) (0 assegnatari)JavaScript (468 fork)user submission
docshelp wanted

Metriche repository

Star
 (5022 stelle)
Metriche merge PR
 (Merge medio 1g 16h) (399 PR mergiate in 30 g)

Descrizione

https://github.com/sindresorhus/eslint-plugin-unicorn/blob/2b469bee475a8f3f2767f4669864acdd89654017/test/no-useless-spread.mjs#L259

[!NOTE] The concat() method preserves empty slots if any of the source arrays is sparse.

via MDN

const foo = new Array(5);
const bar = new Array(5);

const cat = [...foo.concat(bar)];
// now we got a new array with undefined x 10
// but foo.concat(bar) is empty x 10.
// It's not what we want.

Guida contributor