My question pertains to a class named Selection
(which could alternatively be an interface).
The Selection
class may feature a coverage
property with a value of 'all'
or 'selected'
.
If the coverage
property is set to 'selected'
, it can also include an items
value, represented as an array.
I am looking for a way to prevent the existence of the items
property if the coverage
is set to 'all'
.
Here are some code examples:
const allSelected: Selected = {
coverage: 'all',
};
allSelected.items = []; // I want this action to trigger an error since it is trying to access `items`.
const onlySelected: Selected = {
converage: 'selected', // I want this action to trigger an error since it is missing the `items` property.
}
Can the Selection
class be defined in this manner?