How can I optimize typing this nested array of objects?
const myItem: Items[] = [{
id: 1,
text: 'hello',
items: [{
id: 1,
text: 'world'
}]
}]
One way to approach this is by using interfaces:
interface Item {
id: number
text: string
}
interface Items {
id: number // is it necessary to duplicate this?
text: string // is it necessary to duplicate this?
items: Item[]
}
However, I'd like to find a way to eliminate the duplication. It can get messy if the item has more properties.