我不熟悉Type脚本,我正在try 生成一个具有以下形状的对象:
users {
"user1" : {
"startDate" : <timestamp1>
}
"user2" : {
"startDate" : <timestamp2>
}
} 所以我写了这样的话:
type JSONValue =
| string
| number
| boolean
| { [x: string]: JSONValue }
| { JSONValue }
| Array<JSONValue>;
let sessions: JSONValue = [];
let obj: JSONValue = {
this.loggedUser.getName() :
{ "startDate": new Date().getTime() }
}
问题是代码无法编译,因为它不接受属性:this.loggedUser.getName(),如果我放入一个常量字符串,它就可以工作. 另一个问题是我不能创建JSON对象users {},我只能创建一个数组,这就是我使用PUSH的原因……
如有任何帮助,将不胜感激