How would you type this nested array of object?
const myItem: Items[] = [{
id: 1,
text: 'hello',
items: [{
id: 1,
text: 'world'
}]
}]
I could do this
interface Item {
id: number
text: string
}
interface Items {
id: number // avoid this duplication?
text: string // avoid this duplication?
items: Item[]
}
but I wish to get rid of the duplication. If the item has a lot more properties it doesn't look good.
CodePudding user response:
That's exactly what extends
is made for:
interface Items extends Item {
items: Item[]
}