Just for what it's worth, you don't have to declare the type of map
. TypeScript will infer the type from the initializer.
But if you wanted to, it would either be
1. An array of arrays of strings: string[][]
/ Array<Array<string>>
let map: string[][] = [ ['key1', 'value1'],['key2', 'value2'] ] ;
(This is the type TypeScript will infer if you don't specify one.)
Playground link
or
2. An array of string
,string
tuples: [string, string][]
/ Array<[string, string]>
let map: [string,string][] = [ ['key1', 'value1'],['key2', 'value2'] ] ;
Playground link
Tuple types...
...allow you to express an array with a fixed number of elements whose types are known, but need not be the same.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…