-
-
Notifications
You must be signed in to change notification settings - Fork 387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
no-useless-spread
should report when passing spreading parameters to new Set
#2412
Comments
This comment was marked as outdated.
This comment was marked as outdated.
This doesn't mean it can't spread the parameters const foo = [[1,2]]
new Set(...foo) |
It can, but it's unnecessary. const foo = [[1,2]];
new Set(foo[0]); Only the first item will be used in Passing spreading parameters to
|
There's a slight difference I think. However I think it should still report it because the spread only works correctly when const foo = []; // Empty
new Set(...foo) == new Set() == new Set(undefined); // Ok, works just as well const foo = [[1]]; // One
new Set(...foo) == new Set(foo[0]); // Ok, works just as well const foo = [[1], [2]]; // Two
new Set(...foo) == new Set(foo[0], foo[1]); // ❌ Item 2 lost The only caution would be to not autofix it in this case. |
const foo = [[1], [2]]; // Two
new Set(...foo) == new Set(foo[0], foo[1]) == new Set(foo[0]); // Ok, works just as well Auto fixing is safe. Just confidently change all |
That only works if you know the type of |
My fault. const map = new Map([['a','b']]);
new Set(...map); // Set(2) { 'a', 'b' }
new Set(map[0]); // Set(0) {} |
1️⃣ Explain here what's wrong
no-useless-spread
should report error on the codenew Set(...getNames())
. But actually not.Because
new Set()
accept one or zero parameter, we don't need to spread the parameters.Example
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
The text was updated successfully, but these errors were encountered: