1

I cannot find an obvious answer to this question. I am receiving an object from an API where I will be given an object with an id key as a Date and the rest of the keys are random ids with either a number or null value. How can I define an object with dynamic keys?

{
"data": [
    {
        "id": "2021-04-05T04:00:00.000Z",
        "7bfgHyG8TPFJTj7E": 11,
        "7ubSMN7t8kdMe5Kg": 18,
        "aCKx657mBfFq1MJX": 1,
        "be7jxFnkfqvey2xs": 6,
        "Blj2bj1RafiC7Cdw": 15,
        "IW5ERMCxMidbvZEO": 24,
        "iXilJ5OgEGaCtU4l": 31,
        "lE18Nxzrkcyzrpwq": 26,
        "Nxg1fac2TY4EiBYh": 18,
        "SLClljYQt4itnxgP": 8,
        "wNiJjv1ZJH5JuIaT": 110,
        "b9iFwGkBolbppNG1": null,
        "t39dnSJcgS9KjDA0": null,
        "VLFNwtEM3lpX2lmY": null,
        "81eL3E6vdqfY6jiN": null,
        "8zu3HPqdb2QM1fLS": null,
        "uQg4yfefh3RBjsUH": null,
        "jUA9lNtKd4sOSRhl": null,
        "EkGd461QCQWpeYJB": null,
        "vq8AZZEjcM8EkEMT": null,
        "09n1VD1UfajIeWwY": null,
        "FfW2yC7mgBdSRV3t": null,
        "MImuTRjTVHrrFc2D": null,
        "tfuk2tTtaPMX45D3": null
    },
    {
        "id": "2021-04-05T05:00:00.000Z",
        "7bfgHyG8TPFJTj7E": 10,
        "7ubSMN7t8kdMe5Kg": 14,
        "be7jxFnkfqvey2xs": 6,
        "Blj2bj1RafiC7Cdw": 16,
        "IW5ERMCxMidbvZEO": 17,
        "iXilJ5OgEGaCtU4l": 23,
        "lE18Nxzrkcyzrpwq": 24,
        "Nxg1fac2TY4EiBYh": 16,
        "SLClljYQt4itnxgP": 8,
        "wNiJjv1ZJH5JuIaT": 113,
        "aCKx657mBfFq1MJX": null,
        "b9iFwGkBolbppNG1": null,
        "t39dnSJcgS9KjDA0": null,
        "VLFNwtEM3lpX2lmY": null,
        "81eL3E6vdqfY6jiN": null,
        "8zu3HPqdb2QM1fLS": null,
        "uQg4yfefh3RBjsUH": null,
        "jUA9lNtKd4sOSRhl": null,
        "EkGd461QCQWpeYJB": null,
        "vq8AZZEjcM8EkEMT": null,
        "09n1VD1UfajIeWwY": null,
        "FfW2yC7mgBdSRV3t": null,
        "MImuTRjTVHrrFc2D": null,
        "tfuk2tTtaPMX45D3": null
    },

],

}

Jkaram
  • 611
  • 2
  • 7
  • 13
  • 1
    Please look at the [other question](https://stackoverflow.com/questions/61431397/how-to-define-typescript-type-as-a-dictionary-of-strings-but-with-one-numeric-i) and its answer(s); there is unfortunately no specific type in TypeScript that works perfectly here. There are refactorings and workarounds. If you translate the code from that answer here, you get [this](https://tsplay.dev/wOa1Em), which should give you some direction. – jcalz Apr 05 '21 at 19:29

0 Answers0