Skip to content
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

Type inference error for tuples #10581

Closed
jzhang1 opened this issue Aug 28, 2016 · 3 comments
Closed

Type inference error for tuples #10581

jzhang1 opened this issue Aug 28, 2016 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@jzhang1
Copy link

jzhang1 commented Aug 28, 2016

TypeScript Version: 2.0.0

Code

// A *self-contained* demonstration of the problem follows...
coords: [number, number][] = [[0,0], [1,1]];
transformed: [number, number][] = coords.map(([x, y]) => [x+1, y+1]);

Expected behavior:
This type checks

Actual behavior:
coords.map is infered to have type number[][] instead of [number, number][]

@kitsonk
Copy link
Contributor

kitsonk commented Aug 29, 2016

Dupe of #6574

@DanielRosenwasser
Copy link
Member

In the mean time, you can easily fix this by adding a type annotation to map's callback.

coords.map(([x, y]): [number, number] => [x+1, y+1]);

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Aug 29, 2016
@DanielRosenwasser
Copy link
Member

Thanks for deduping @kitsonk!

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants