Optional Iterator parameter "incorrectly" accepts spread arguments
See original GitHub issuedeclare const strs1: string[];
declare const strs2: IterableIterator<string>;
declare function badFoo(x?: Iterable<string>): void
// This function is BAD.
// The last two calls are INCORRECTLY accepted.
badFoo(strs1); // accepted - fine
badFoo(strs2); // accepted - fine
badFoo(...strs1); // accepted, BAD ❌
badFoo(...strs2); // accepted, BAD ❌
Issue Analytics
- State:
- Created a year ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
A spread argument must either have a tuple type or be passed ...
A spread argument must either have a tuple type or be passed to a rest parameter. Can someone can help my, how I...
Read more >Spread syntax (...) - JavaScript - MDN Web Docs - Mozilla
The spread (...) syntax allows an iterable, such as an array or string, to be expanded in places where zero or more arguments...
Read more >typescript spread arguments type - Lena's Italian Restaurant
Where callbackFn takes three arguments:. Returns a new array iterator that contains the keys for each index in the calling array. TypeScript has...
Read more >Javascript's Awesome Spread Syntax[…] | by Steven Ellis
Spread syntax allows an iterable or to be expanded in places where zero or more arguments (for function calls) or elements (for array...
Read more >Iterables - The Modern JavaScript Tutorial
Iterable objects are a generalization of arrays. That's a concept that allows us to make any object useable in a for..of loop.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@bschnurr thanks 😄
Ultimately I think it’s a case where
string
s being at all compatible withIterable<string>
is extremely suspicious unless it’s made explicit with a type assertion. Seems a bit heavy-handed, but I can’t think of the last time I needed to spread a string except for emoji examples.