I'm struggling to define a TypeScript type for data in the following structure (comes from a Neptune/neo4J database). The object in the results array may have 0+ keys. The names of the keys (in this example a
, m
and d
are arbitrary however the structure of each value object will always contain the three fields Name
, Description
and online
are always going to be present.
{
"results": [
{
"a": {
"properties": {
"Name": "B-01",
"Description": "first item",
"online": true
}
},
"m": {
"properties": {
"Name": "A32RD",
"Description": "another item",
"online": false
}
},
"d": {
"properties": {
"Name": "ANO123",
"Description": "third item",
"online": true
}
}
}
]
}
Can anyone suggest how I could define this type? Alternatively are there any predefined types for Neptune / Neo4J?
Thanks
You can define this type like this:
interface Properties {
Name: string;
Description: string;
online: boolean;
}
interface Result {
[key: string]: {
properties: Properties;
};
}
interface ResultData {
results: Result[];
}