You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
What it type [[string, number]] vs [string, number][] #3428
var items: [[string, number]];
for (let item of items) { // item: [string, number]
let name = item[0]; // name: string
let quantity = item[1]; // quantity: number
}
var items: [string, number][];
for (let item of items) { // item: [string, number]
let name = item[0]; // name: string
let quantity = item[1]; // quantity: number
}
They look the same but can't assign to each other:
var a: [[string, number]];
var b: [string, number][];
a = b.map(c => c); // Error: Type '[string, number][]' is not assignable to type '[[string, number]]'. Property '0' is missing in type '[string, number][]'
a = b.map(c => [c[0], c[1]]); // Error: Type '(string | number)[][]' is not assignable to type '[[string, number]]'. Property '0' is missing in type '(string | number)[][]'
b = a.map(c => c); // OK
b = a.map(c => [c[0], c[1]]); // Error: Type '(string | number)[][]' is not assignable to type '[[string, number]]'. Type '(string | number)[]' is not assignable to type '[string, number]'. Property '0' is missing in type '(string | number)[]'
Activity
DanielRosenwasser commentedon Jun 8, 2015
[[string, number]]is a single-element tuple where the element has the type[string, number].[string, number][]is an array of[string, number]tuples.Homa Wong (@unional), I think questions such as these would be better fit for either StackOverflow or our Gitter room.
unional commentedon Jun 8, 2015
Thanks. Didn't know gitter room exist. Will move questions like these over there.
DanielRosenwasser commentedon Jun 8, 2015
No worries - we only recently got the Gitter room so it's easy to miss.
declare array properties as arrays, not tuples
declare array properties as arrays, not tuples
declare array properties as arrays, not tuples (#14964)
declare array properties as arrays, not tuples (DefinitelyTyped#14964)