-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Array of tuple literal not assignable to iterable of tuple with --lib es2015 -t es5 #32761
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
Comments
Cloned repo, ran Are you sure you don't have another |
Are you able to reproduce the error with I am finding that However, I'm targeting ES5 (and polyfilling ES2015 features). And the library I'm using, Facebook's ImmutableJS, presumably has to target a range of ES versions, so they want to reference Is this expected behavior with |
If |
But that makes It looks like adding |
@RyanCavanaugh Actually, I'm confused why So why isn't The docs for |
Actually no, this seems like an issue with type inference. In most cases (not
In this Playground Link, the first 4 examples here all show that Both |
When compiling TypeScript targeting ES5, if --downlevelIteration isn't used, then arrays of tuples won't be considered assignable to iterables of tuples, resulting in type errors when doing common things like Map([['key', 'value']]): microsoft/TypeScript#32761 --downlevelIteration hurts runtime performance of for..of loops on arrays, but a type definition-only workaround is to explicitly include arrays or array sof tuples in parameter types or function overloads.
@RyanCavanaugh just updated title, code sample, and Playground link to succinctly illustrate that |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow. |
@RyanCavanaugh Can you unmark this as a Question? I think the updated code sample succinctly illustrates that it's a bug |
Looking |
@rbuckton can you explain what's happening? Bug? |
Uh oh!
There was an error while loading. Please reload this page.
TypeScript Versions: 3.5.1, 3.5.3 (currently
typescript@latest
), 3.6.0-beta (currentlytypescript@beta
), 3.6.0-dev.20190808 (currentlytypescript@next
)Search Terms:
Code
Expected behavior: variable
y
is inferred to be of type[number, string]
and parameterj
is inferred to be of typeArray<[number, string]>
Actual behavior:
error TS2345: Argument of type '(string | number)[][]' is not assignable to parameter of type 'Iterable<[string | number, string | number]>'.
Playground Link
Related Issues: maybe #29311 ?
The text was updated successfully, but these errors were encountered: