-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
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)[]'
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code