My data is structured as shown below:
let equipment:Equipment = {
"1": {
"name": "abc",
"data": 123
},
"2": {
"name": "def",
"data": 234
},
"3": {
"name": "ghi",
"data": 345
},
...
}
Converting this into an array seems straightforward, but since my equipment ID's start with 1, I'd prefer not to deal with the logic of excluding the [0] element (which would be null).
To address this, I have created the TypeScript Declaration Files below.
interface Equipment
{
[ k: number ]: EquipmentBase;
}
interface EquipmentBase
{
name: string
data: number
}
Furthermore, when I return this equipment object alongside others, I need to place it in a JSON object, requiring yet another interface declaration.
interface EquipmentObj
{
equipment: Equipment
}
/* returns {equipment:
{
"1": {
"name": "abc",
"data": 123
},
"2": {
"name": "def",
"data": 234
},
"3": {
"name": "ghi",
"data": 345
},
...
}
}
*/
It seems like a lot of declarations (Equipment, EquipmentObj) are needed just to define an object that stores data. Is there a more efficient way to reduce the number of declarations I'm using?