【发布时间】:2017-04-20 12:05:02
【问题描述】:
假设我在 Typescript 中有这个定义的类:
class Data{
Dimension1: string;
Dimension2: string;
Metrics: Array<string>;
}
有没有办法我可以用下面的 json 数据声明一个 Data 实例(小写的属性)?
let json: Data = {
"dimension1": "some dim",
"dimension2": "some other dimes",
"metrics": ["metric1", "metric2"]
}
目前,编译器会抱怨 Type 的属性不兼容。
【问题讨论】:
-
没有。这有什么用? JS 键名区分大小写。
标签: json typescript