question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optional Iterator parameter "incorrectly" accepts spread arguments

See original GitHub issue
declare 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 ❌

Playground Link

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jakebaileycommented, Apr 5, 2022

@bschnurr thanks 😄

0reactions
DanielRosenwassercommented, Apr 8, 2022

Ultimately I think it’s a case where strings being at all compatible with Iterable<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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found