Skip to content

map() type inference incomplete #19868

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

Closed
ithinkihaveacat opened this issue Nov 9, 2017 · 3 comments
Closed

map() type inference incomplete #19868

ithinkihaveacat opened this issue Nov 9, 2017 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@ithinkihaveacat
Copy link

Code

const foo = [1, 2, 3].map(() => [1, 2]);
const bar = new Map<number, number>(foo)

Expected behavior:

No error.

Actual behavior:

Type error: Argument of type 'number[][]' is not assignable to parameter of type '[number, number][]'. In this case, foo will always be of the form [number, number][].

screenshot from 2017-11-09 11 23 36

@kitsonk
Copy link
Contributor

kitsonk commented Nov 9, 2017

Essentially duplicate of #16360 (and several other related issues). At the moment, tuple types are never inferred and have to be asserted.

@ghost ghost added the Duplicate An existing issue was already created label Nov 9, 2017
@aluanhaddad
Copy link
Contributor

In the case of Array.prototype.map, you can write

interface Array<T> {
  map<U, V>(callbackfn: (value: T, index: number, array: T[]) => [U, V], thisArg?: {}): [U, V][];
}
const foo = [1, 2, 3].map(() => [1, 2]);
const bar = new Map(foo);

which will resolve this specific error.

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 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

4 participants