-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path28 ~ Exercise: DaysWith - MealsWithIngredient.ts
44 lines (39 loc) · 1.36 KB
/
28 ~ Exercise: DaysWith - MealsWithIngredient.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Task: Given an ingredient, say on which day you can eat it
// To help: start with figuring out which meals use this ingredient
type Menu = {
Monday: ["Steak and lettuce", "Codd and tomatoes"]
Tuesday: ["Chicken and carrots", "Peas and carrots"]
Wednesday: ["Fish and chips", "Turkey and stuffing"]
Thursday: ["Sushi and rice", "Wok and noodles"]
Friday: ["Lamb and tomatoes", "Salmon and cheese"]
Saturday: ["Spaghetti and pesto", "Penne and arrabiata"]
Sunday: ["Fries and ketchup", "Fries and mayonnaise"]
}
/*
*
*
*
*/
type MealsWithIngredient<Ingredient extends string> = any
// type MealsWithSteak = "Steak and lettuce"
type MealsWithSteak = MealsWithIngredient<"Steak">
// type MealsWithFries = "Fries and ketchup" | "Fries and mayonnaise"
type MealsWithFries = MealsWithIngredient<"Fries">
// type MealsWithTomatoes = "Codd and tomatoes" | "Lamb and tomatoes"
type MealsWithTomatoes = MealsWithIngredient<"tomatoes">
// type MealsWithHummus = never
type MealsWithHummus = MealsWithIngredient<"hummus">
/*
*
*
*
*/
type DaysWith<I extends string> = any
// type DaysWithSteak = "Monday"
type DaysWithSteak = DaysWith<"Steak">
// type DaysWithFries = "Sunday"
type DaysWithFries = DaysWith<"Fries">
// type DaysWithTomatoes = "Monday" | "Friday"
type DaysWithTomatoes = DaysWith<"tomatoes">
// type DaysWithHummus = never
type DaysWithHummus = DaysWith<"hummus">