I have this list of dishes:
const dishes = [
{
id: 'dish01',
title: 'SALMON CRUNCH',
price: 99,
ingredients: [
'SALMON',
'CRUNCH SALAD',
],
options: [
{
option: 'BASE',
choices: ['RICE', 'SPAGHETTI', 'MIX'],
defaultOption: 'MIX',
},
],
},
{
id: 'dish02',
title: 'GOCHUJANG CHICKEN',
price: 110,
ingredients: [
'GOCHUJANG',
'CHICKEN',
],
options: [
{
option: 'BASE',
choices: ['RICE', 'SPAGHETTI', 'MIX'],
defaultOption: 'MIX',
},
{
option: 'TOPPING',
choices: ['MAYO', 'KETCHUP', 'NONE'],
defaultOption: 'NONE',
},
],
},
...
]
I then decide to use a useReducer
(React) to keep track and build a single dish order object that goes into the card.
Is it then possible define a custom interface for each dish?
// types for dish01
type Ingredients = 'SALMON' | 'CRUNCH SALAD'
interface DishOrder {
id: string
withoutIngredients: Ingredients[]
BASE: 'RICE' | 'SPAGHETTI' | 'MIX'
}
// types for dish02
type Ingredients = 'GOCHUJANG' | 'CHICKEN'
interface DishOrder {
id: string
withoutIngredients: Ingredients[]
BASE: 'RICE' | 'SPAGHETTI' | 'MIX'
TOPPINGS: 'MAYO' | 'KETCHUP' | 'NONE'
}
if not, is this then as typed as it can get:
interface DishOptions {
[key: string]: string
}
// https://stackoverflow.com/a/45261035/618099
type DishOrder = DishOptions & {
id: string
withoutIngredients: string[]
}