From 7ed682683b6e5e025f2a5e013401ddc1d6427e33 Mon Sep 17 00:00:00 2001 From: Matt Pocock Date: Wed, 23 Aug 2023 10:34:13 +0100 Subject: [PATCH] 2023-08-23T09:34:13.591Z --- .../104-typeof-keyword.problem.ts | 0 .../104-typeof-keyword.solution.ts | 0 ...reate-runtime-values-from-types.problem.ts | 0 ...eate-runtime-values-from-types.solution.ts | 0 .../106-return-type.problem.ts | 0 .../106-return-type.solution.ts | 0 .../107-parameters-type-helper.problem.ts | 0 .../107-parameters-type-helper.solution.ts | 0 .../108-keyof.problem.ts | 0 .../108-keyof.solution.ts | 0 .../109-indexed-access-types.problem.ts | 0 .../109-indexed-access-types.solution.ts | 0 ...-unions-to-indexed-access-types.problem.ts | 0 ...unions-to-indexed-access-types.solution.ts | 0 ...yof-into-an-indexed-access-type.problem.ts | 0 ...of-into-an-indexed-access-type.solution.ts | 0 ...te-an-enum-from-as-const-object.problem.ts | 0 ...e-an-enum-from-as-const-object.solution.ts | 0 ...-a-union-from-an-as-const-array.problem.ts | 0 ...a-union-from-an-as-const-array.solution.ts | 0 ...-should-i-use-enums-or-as-const.problem.ts | 0 ...should-i-use-enums-or-as-const.solution.ts | 0 src/040-deriving-types-from-values/plan.md | 34 +++++++++++++++++++ 23 files changed, 34 insertions(+) create mode 100644 src/040-deriving-types-from-values/104-typeof-keyword.problem.ts create mode 100644 src/040-deriving-types-from-values/104-typeof-keyword.solution.ts create mode 100644 src/040-deriving-types-from-values/105-create-runtime-values-from-types.problem.ts create mode 100644 src/040-deriving-types-from-values/105-create-runtime-values-from-types.solution.ts create mode 100644 src/040-deriving-types-from-values/106-return-type.problem.ts create mode 100644 src/040-deriving-types-from-values/106-return-type.solution.ts create mode 100644 src/040-deriving-types-from-values/107-parameters-type-helper.problem.ts create mode 100644 src/040-deriving-types-from-values/107-parameters-type-helper.solution.ts create mode 100644 src/040-deriving-types-from-values/108-keyof.problem.ts create mode 100644 src/040-deriving-types-from-values/108-keyof.solution.ts create mode 100644 src/040-deriving-types-from-values/109-indexed-access-types.problem.ts create mode 100644 src/040-deriving-types-from-values/109-indexed-access-types.solution.ts create mode 100644 src/040-deriving-types-from-values/110-pass-unions-to-indexed-access-types.problem.ts create mode 100644 src/040-deriving-types-from-values/110-pass-unions-to-indexed-access-types.solution.ts create mode 100644 src/040-deriving-types-from-values/111-pass-keyof-into-an-indexed-access-type.problem.ts create mode 100644 src/040-deriving-types-from-values/111-pass-keyof-into-an-indexed-access-type.solution.ts create mode 100644 src/040-deriving-types-from-values/112-create-an-enum-from-as-const-object.problem.ts create mode 100644 src/040-deriving-types-from-values/112-create-an-enum-from-as-const-object.solution.ts create mode 100644 src/040-deriving-types-from-values/113-create-a-union-from-an-as-const-array.problem.ts create mode 100644 src/040-deriving-types-from-values/113-create-a-union-from-an-as-const-array.solution.ts create mode 100644 src/040-deriving-types-from-values/114-should-i-use-enums-or-as-const.problem.ts create mode 100644 src/040-deriving-types-from-values/114-should-i-use-enums-or-as-const.solution.ts create mode 100644 src/040-deriving-types-from-values/plan.md diff --git a/src/040-deriving-types-from-values/104-typeof-keyword.problem.ts b/src/040-deriving-types-from-values/104-typeof-keyword.problem.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/104-typeof-keyword.solution.ts b/src/040-deriving-types-from-values/104-typeof-keyword.solution.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/105-create-runtime-values-from-types.problem.ts b/src/040-deriving-types-from-values/105-create-runtime-values-from-types.problem.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/105-create-runtime-values-from-types.solution.ts b/src/040-deriving-types-from-values/105-create-runtime-values-from-types.solution.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/106-return-type.problem.ts b/src/040-deriving-types-from-values/106-return-type.problem.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/106-return-type.solution.ts b/src/040-deriving-types-from-values/106-return-type.solution.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/107-parameters-type-helper.problem.ts b/src/040-deriving-types-from-values/107-parameters-type-helper.problem.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/107-parameters-type-helper.solution.ts b/src/040-deriving-types-from-values/107-parameters-type-helper.solution.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/108-keyof.problem.ts b/src/040-deriving-types-from-values/108-keyof.problem.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/108-keyof.solution.ts b/src/040-deriving-types-from-values/108-keyof.solution.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/109-indexed-access-types.problem.ts b/src/040-deriving-types-from-values/109-indexed-access-types.problem.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/109-indexed-access-types.solution.ts b/src/040-deriving-types-from-values/109-indexed-access-types.solution.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/110-pass-unions-to-indexed-access-types.problem.ts b/src/040-deriving-types-from-values/110-pass-unions-to-indexed-access-types.problem.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/110-pass-unions-to-indexed-access-types.solution.ts b/src/040-deriving-types-from-values/110-pass-unions-to-indexed-access-types.solution.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/111-pass-keyof-into-an-indexed-access-type.problem.ts b/src/040-deriving-types-from-values/111-pass-keyof-into-an-indexed-access-type.problem.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/111-pass-keyof-into-an-indexed-access-type.solution.ts b/src/040-deriving-types-from-values/111-pass-keyof-into-an-indexed-access-type.solution.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/112-create-an-enum-from-as-const-object.problem.ts b/src/040-deriving-types-from-values/112-create-an-enum-from-as-const-object.problem.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/112-create-an-enum-from-as-const-object.solution.ts b/src/040-deriving-types-from-values/112-create-an-enum-from-as-const-object.solution.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/113-create-a-union-from-an-as-const-array.problem.ts b/src/040-deriving-types-from-values/113-create-a-union-from-an-as-const-array.problem.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/113-create-a-union-from-an-as-const-array.solution.ts b/src/040-deriving-types-from-values/113-create-a-union-from-an-as-const-array.solution.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/114-should-i-use-enums-or-as-const.problem.ts b/src/040-deriving-types-from-values/114-should-i-use-enums-or-as-const.problem.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/114-should-i-use-enums-or-as-const.solution.ts b/src/040-deriving-types-from-values/114-should-i-use-enums-or-as-const.solution.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/040-deriving-types-from-values/plan.md b/src/040-deriving-types-from-values/plan.md new file mode 100644 index 0000000..ddbb824 --- /dev/null +++ b/src/040-deriving-types-from-values/plan.md @@ -0,0 +1,34 @@ +# Title + +Deriving types from values + +## Exercises + +LEARNING GOAL: Understand the type world and the runtime world. +CONFUSION: Can I create runtime values from types? +LEARNING GOAL: Understand the `typeof` keyword. +CONFUSION: Is this the same as the JavaScript keyword? + +LEARNING GOAL: You can only create types from runtime values, not the other way around. + +LEARNING GOAL: Use `ReturnType` to get the return type of a function. +NOTEWORTHY: This is really good for extracting the return value of a third-party function. + +LEARNING GOAL: Use `Parameters` to get the parameters of a function. + +LEARNING GOAL: Understand the `keyof` keyword +CONFUSION: Why do we have to do `keyof typeof` instead of just `keyof`? + +LEARNING GOAL: Understand indexed access types +CONFUSION: Why can't I just use `.name` instead of `['name']`? + +LEARNING GOAL: Understand that you can pass unions into indexed access types. + +LEARNING GOAL: Understand that you can pass `keyof` into an indexed access type. + +LEARNING GOAL: Create an enum from an `as const` object. + +LEARNING GOAL: Create an enum from an `as const` array. +LEARNING GOAL: Understand the `T[number]` syntax. + +CONFUSION: Should I use enums, or 'as const' objects?