Imagine having a recipe ingredient type structured like this
export type RecipeIngredient = {
name: string;
amount: Number | string;
unit: "grams" | "milliliters" | "custom";
};
To illustrate
const apples: RecipeIngredient = { name: 'apples', amount: 200, unit: 'grams' }
This setup works well, but the requirement is to allow the amount to be a string only when the unit is considered custom. Is this achievable?
The ideal scenario
const vanillaExtract: RecipeIngredient = { name: 'vanilla extract', amount: 'a dash', unit: 'custom' }
What should be considered incorrect
const milk: RecipeIngredient = { name: 'milk', amount: '500ml', unit: 'milliliters' }