如何在打字稿中声明一个Map类型?

时间:2016-07-20 17:24:38

标签: typescript

我想声明一个这样的类型:

interface DependData {[key: string]: string};

但是有这样的错误:

Statements are not allowed in ambient contexts

1 个答案:

答案 0 :(得分:6)

您描述的错误消息发生在定义文件中。

要使其工作,您需要使用正确的语法并删除接口声明末尾的分号:

interface DependData {
    [key: string]: string;
}