My web service returns an array of objects that looks like this:
[ { "abc": "test 1" }, { "def": "test 2" }, { "ghi": "test 3" } ]
Now I want to declare a TypeScript interface for this result. But I have no idea how to do that because the key of each object can be string whose name varies.
Specifically:
From the code you provided, I suggest using:
const a: { [key: string]: string }[] = [ { "abc": "test 1" }, { "def": "test 2" }, { "ghi": "test 3" } ]
It is a string indexed object with string values.
string
1.4m articles
1.4m replys
5 comments
57.0k users