1️⃣ Explain here what's wrong
function getNames() {
return ['foo', 'bar', 'foo'];
}
const uniqueNames = [...new Set(...getNames())]; // I mistakenly spreading the `getNames()`
console.log(uniqueNames) // Print [ 'f', 'o' ]. But what I expect is ['foo', 'bar']
no-useless-spread
should report error on the code new Set(...getNames())
. But actually not.
Because new Set()
accept one or zero parameter, we don't need to spread the parameters.
Example
const foo = ['abc'];
const set = new Set(...foo); // BAD!
const set = new Set(foo[0]); // OK
2️⃣ Specify which rule is buggy here and in the title
no-useless-spread
3️⃣ More information
TypeScript should report error when compiling the code above. Unfortunately, this problem havn't been fixed yet. Set microsoft/TypeScript#59390 and microsoft/TypeScript#48575
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too