Lets say I have 2 interfaces.
interface ItemGroup {
itemDefaults: Partial<Item>
items: Item[]
}
interface Item {
price?: number
size?: string
}
I want to make sure the attribute is provided in default or the Item. Its fine if both are provided, but at least one should be required.
//Should be Valid
[{
"itemDefaults": {
"price": 10,
"size": "L"
},
"items": [
{
"size": "M"
}
]
}]
//Should be Invalid as both itemDefaults and Item is missing size
[{
"itemDefaults": {
"price": 10
},
"items": [
{
"price": 12
}
]
}]
Is there a way to enforce something like this in TypeScript?