microsoft / microsoft/TypeScript
Array of tuple literal not assignable to iterable of tuple with --lib es2015 -t es5
Open
@rbuckton is already working on this.
Since Aug 16, 2019.
Needs Investigation
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Versions: 3.5.1, 3.5.3 (currently typescript@latest), 3.6.0-beta (currently typescript@beta), 3.6.0-dev.20190808 (currently typescript@next)
Search Terms:
Code
// Works:
declare function foo<T>(i: Iterable<T>): T
const x = foo([1]); // infers a: number
// Fails:
declare function bar<T, U>(j: Iterable<[T, U]>): [T, U]
const y = bar([[1, 'a']]);
// ^^^^^^^^
// Argument of type '(string | number)[][]' is not assignable to
// parameter of type 'Iterable<[string | number, string | number]>'.
// workaround:
declare function qux<T, U>(j: Array<[T, U]> | Iterable<[T, U]>): [T, U]
const z = qux([[1, 'a']]); // infers z: [number, string]
Expected behavior: variable y is inferred to be of type [number, string] and parameter j is inferred to be of type Array<[number, string]>
Actual behavior: error TS2345: Argument of type '(string | number)[][]' is not assignable to parameter of type 'Iterable<[string | number, string | number]>'.
Related Issues: maybe #29311 ?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.