I am dealing with the code snippet provided below:
type Chocolate = {
'flavour': 'Chocolate',
'calories': 120
}
type Vanilla = {
'flavour': 'Vanilla',
'calories': 90
}
type Mango = {
'flavour': 'Mango',
'calories': 110
}
type Mint = {
'flavour': 'Mint',
'calories': 100
}
type UseCase = Chocolate | Vanilla | Mango | Mint;
export const chocolate: Chocolate = {
'flavour': 'Chocolate',
'calories': 120
}
export const vanilla: Vanilla = {
'flavour': 'Vanilla',
'calories': 90
}
export const mint: Mint = {
'flavour': 'Mint',
'calories': 100
}
export const mango: Mango = {
'flavour': 'Mango',
'calories': 110
}
The structure of the code seems quite verbose. Is there a way to efficiently use types as values (or vice versa) since they're essentially similar?
Note that all calorie values are fixed within predefined ranges (i.e., 90/100/110/120), so it's not just a generic number.