The structure of JSON that is received from the server is something like this(I changed details):
{
"apple": {
"fruitName": "apple",
"types": {
"greenApple": {
"productCode": "P1",
"productName": "Green Apple",
"color": "green",
},
"galaApple": {
"productCode": "P2",
"productName": "Gala Apple",
"color": "light red",
},
"redDelicious": {
"productCode": "P3",
"productName": "Red delicious apple",
"color": "bright red",
}
}
},
"orange": {
"fruitName": "orange",
"types": {
"mandarin": {
"productCode": "P5",
"productName": "Mandarin Oranges",
"color": "orange",
},
"bloodOrange": {
"productCode": "P6",
"productName": "Blood Orange",
"color": "red",
}
}
},
}
I am coming up with an Interface structure using Typescript for my project.
So far I have come up with this:
export type FruitTypes = {
[key: string]: Product,
}
export type Product = {
productCode: string
productName: string
color: string
}
export type Fruits = {
fruitName: string
type: object<FruitTypes>
}
What I am not understanding is how to make a declaration in Fruits for type?
type: object<FruitTypes> is not working. It is going to be an object of objects. How do we describe this in Typescript.
type: FruitTypes?