使用打字稿声明地图

时间:2017-03-30 15:14:21

标签: javascript dictionary typescript

private itemsMap: Map<Array<string>,string> = new Map([
    [['shp'], 'Shapefile'],
    [['doc', 'docx'], 'Microsoft Word']
]);

打字稿并不是这样的,它给了我:&#34;类型的参数&#39;(字符串|字符串[])[] []&#39;不能分配给类型参数&#39; Iterable&lt; [{},{}]&gt;&#34;

这是宣布&#34; Map literal&#34;的有效方法。虽然。有没有办法做到这一点不会导致问题?

1 个答案:

答案 0 :(得分:0)

使用什么TypeScript版本?这似乎可以正常使用当前的TypeScript版本(目前为2.2.x)。

See this playground