I'm no expert in Typescript, but I think the main problem is the way of accessing data. Seeing how you described your Images
interface, you can define any key as a String.
When accessing a property, the "dot" syntax (images.main
) supposes, I think, that it already exists. I had such problems without Typescript, in "vanilla" Javascript, where I tried to access data as:
return json.property[0].index
where index was a variable. But it interpreted index
, resulting in a:
cannot find property "index" of json.property[0]
And I had to find a workaround using your syntax:
return json.property[0][index]
It may be your only option there. But, once again, I'm no Typescript expert, if anyone knows a better solution / explaination about what happens, feel free to correct me.