As a beginner in Type Script, I am currently working on creating an object with a specific structure:
users {
"user1" : {
"startDate" : <timestamp1>
}
"user2" : {
"startDate" : <timestamp2>
}
} In my attempt to achieve this, I came up with the following solution:
type JSONValue =
| string
| number
| boolean
| { [x: string]: JSONValue }
| { JSONValue }
| Array<JSONValue>;
let sessions: JSONValue = [];
let obj: JSONValue = {
this.loggedUser.getName() :
{ "startDate": new Date().getTime() }
}
However, the code failed to compile due to the rejection of the property: this.loggedUser.getName(). When I used a constant string instead, it worked fine. Additionally, I encountered an issue where I was unable to create a JSON object users {}, so I resorted to using push to handle an array instead.
Any assistance on this matter would be greatly appreciated.