Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Some Starting Challenges (#844)

Dimitri Mitropoulosde0987e4b933
diff --git a/challenges/blank/metadata.json b/challenges/blank/metadata.json
new file mode 100644
index 00000000..6d38c914
--- /dev/null
+++ b/challenges/blank/metadata.json
@@ -0,0 +1,4 @@
+{
+ "id": "lower-snake-case",
+ "prerequisites": []
+}
diff --git a/challenges/blank/prompt.md b/challenges/blank/prompt.md
new file mode 100644
index 00000000..82c2a7b8
--- /dev/null
+++ b/challenges/blank/prompt.md
@@ -0,0 +1,11 @@
+## What Problem XYZ Solves
+
+Explain: why this is important or useful knowledge
+
+## How To Use XYZ
+
+What's the API of the type? What generics and in what order?
+
+## Solving This Challenge
+
+Short and to-the-point. Should be _possible_ to skip everything above and just read this.
diff --git a/challenges/blank/solutions/1.ts b/challenges/blank/solutions/1.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/challenges/blank/tests.ts b/challenges/blank/tests.ts
new file mode 100644
index 00000000..78123de9
--- /dev/null
+++ b/challenges/blank/tests.ts
@@ -0,0 +1 @@
+import { Expect, Equal } from 'type-testing';
diff --git a/challenges/blank/tsconfig.json b/challenges/blank/tsconfig.json
new file mode 100644
index 00000000..875cb600
--- /dev/null
+++ b/challenges/blank/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/challenges/blank/user.ts b/challenges/blank/user.ts
new file mode 100644
index 00000000..5c69415c
--- /dev/null
+++ b/challenges/blank/user.ts
@@ -0,0 +1 @@
+type XYZ = unknown;
diff --git a/challenges/generic-type-arguments/metadata.json b/challenges/generic-type-arguments/metadata.json
new file mode 100644
index 00000000..4387de31
--- /dev/null
+++ b/challenges/generic-type-arguments/metadata.json
@@ -0,0 +1,4 @@
+{
+ "id": "generic-type-arguments",
+ "prerequisites": ["primitive-data-types", "type-aliases"]
+}
diff --git a/challenges/generic-type-arguments/prompt.md b/challenges/generic-type-arguments/prompt.md
new file mode 100644
index 00000000..ec3f5fe2
--- /dev/null
+++ b/challenges/generic-type-arguments/prompt.md
@@ -0,0 +1,95 @@
+## Why We Need Generic Type Arguments
+
+If primitive (and literal) types are data, you can think of generics as functions that operate on that data.
+
+And just like functions often need arguments, we need some way to provide inputs to generic types.
+
+## How To Use Generic Arguments
+
+Instead of using parenthesis to pass arguments, with generics we use angled brackets: `<` and `>`.
+
+Other than that, there are a lot of similarities between the two concepts.
+
+> You can even provide defaults for generic arguments! See the relevant challenge for [generic defaults](todo-link).
+
+There are two separate situations when you'd use this syntax. One is when you're working strictly with types, and another is when you're doing more normal JavaScript-y stuff like with functions and constants.
+
+### Universe 1: strictly in the type system
+
+Just take a look:
+
+```ts
+interface Row<T> {
+ label: string;
+ value: T;
+ disabled: boolean;
+}
+```
+
+> Note: It's common (and acceptable) in situations like this where we _really don't know anything else_ about the Generic type parameter to use a single letter like `T`. But the moment you have multiple arguments (or more context for what this type will be) it's a good idea to use more descriptive names.
+
+What this syntax means is that we have a `Row` type, and we know it will have a `value` property, but the _specific type_ of that `value` property is not known until it's used.
+
+We could store `number`s in this `Row` type. If we did, it'd look like this:
+
+```ts
+type NumberRow = Row<number>
+```
+
+Or we could store `string`s:
+
+```ts
+type StringRow = Row<string>
+```
+
+Because TypeScript is a structural type system, `Row<string>` is exactly equivalent (in every way) to if we had written this:
+
+```ts
+type StringRow = {
+ label: string;
+ value: string;
+ disabled: boolean;
+}
+```
+
+But because we used a generic, we didn't have to type all that other stuff out every time.
+
+### Multiple Generic Arguments
+
+Just like functions can take multiple arguments, so too can Generics.
+
+```ts
+type GroceryItem<Name, Price, InStock> = {
+ name: Name;
+ price: Price;
+ inStock: InStock;
+}
+```
+
+Now you can change pass arguments to this type:
+
+```ts
+type AvocadoToast = GroceryItem<
+ 'Avocado Toast',
+ 12.99,
+ true
+>
+```
+
+This is exactly equal to if you had written:
+
+```ts
+type AvocadoToast = {
+ name: 'Avocado Toast',
+ price: 12.99,
+ inStock: true
+}
+```
+
+> Note: you might notice that we're missing types for our type arguments! Right now there's nothing stopping us from sending in wrong values like `GroceryItem<number[], boolean, { over: 9000 }>`. We'll cover that in a future challenge on [`generic-constraints`](todo-link).
+
+## Solving This Challenge
+
+Similar to what we did with `AvocadoToast`, create a `CapreseSalad` type, and fill in the right values to make the tests pass.
+
+Then, create a new generic type for `GroceryStore`. Let the tests guide you regarding what the final type should look like and what the inputs should be.
diff --git a/challenges/generic-type-arguments/solutions/1.ts b/challenges/generic-type-arguments/solutions/1.ts
new file mode 100644
index 00000000..8f2abf82
--- /dev/null
+++ b/challenges/generic-type-arguments/solutions/1.ts
@@ -0,0 +1,6 @@
+type CapreseSalad = GroceryItem<'Caprese Salad', 14.99, true>;
+
+type GroceryStore<Name, City> = {
+ name: Name;
+ city: City;
+}
diff --git a/challenges/generic-type-arguments/tests.ts b/challenges/generic-type-arguments/tests.ts
new file mode 100644
index 00000000..b790e5ce
--- /dev/null
+++ b/challenges/generic-type-arguments/tests.ts
@@ -0,0 +1,26 @@
+import { Expect, Equal } from 'type-testing';
+
+type test_CapreseSaladName = Expect<Equal<
+ CapreseSalad['name'],
+ 'Caprese Salad'
+>>;
+
+type test_CapreseSaladPrice = Expect<Equal<
+ CapreseSalad['price'],
+ 14.99
+>>;
+
+type test_CapreseSaladInStock = Expect<Equal<
+ CapreseSalad['inStock'],
+ true
+>>;
+
+type test_KrogerDetroit = Expect<Equal<
+ GroceryStore<'Kroger', 'Detroit'>,
+ { name: 'Kroger', city: 'Detroit' }
+>>;
+
+type test_StopNShopMassachusetts = Expect<Equal<
+ GroceryStore<'Stop \'N Shop', 'Massachusetts'>,
+ { name: 'Stop \'N Shop', city: 'Massachusetts' }
+>>;
diff --git a/challenges/generic-type-arguments/tsconfig.json b/challenges/generic-type-arguments/tsconfig.json
new file mode 100644
index 00000000..875cb600
--- /dev/null
+++ b/challenges/generic-type-arguments/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/challenges/generic-type-arguments/user.ts b/challenges/generic-type-arguments/user.ts
new file mode 100644
index 00000000..245354f2
--- /dev/null
+++ b/challenges/generic-type-arguments/user.ts
@@ -0,0 +1,3 @@
+type CapreseSalad = unknown;
+
+type GroceryStore = unknown;
diff --git a/challenges/generic-type-constraints/metadata.json b/challenges/generic-type-constraints/metadata.json
new file mode 100644
index 00000000..94dccec0
--- /dev/null
+++ b/challenges/generic-type-constraints/metadata.json
@@ -0,0 +1,4 @@
+{
+ "id": "generic-type-constraints",
+ "prerequisites": []
+}
diff --git a/challenges/generic-type-constraints/prompt.md b/challenges/generic-type-constraints/prompt.md
new file mode 100644
index 00000000..a4d5250e
--- /dev/null
+++ b/challenges/generic-type-constraints/prompt.md
@@ -0,0 +1,87 @@
+## The Problem Generic Type Constraints Solve
+
+Generics are an incredibly powerful tool in TypeScript. In a [previous challenge](todo-generic-type-arguments) where generic type arguments were introduced, we compared them to function arguments _but for types_.
+
+Consider the parallel of these two:
+
+```ts
+// v-----v argument identifier
+const drive = (carType: CarType) => {
+ // ^-------^ argument type constraint
+ // ....
+}
+
+// v-------v type parameter identifier
+type Drive<CarType> = (carType: CarType) => {
+ // ....
+}
+```
+
+Notice that there's no type constraint for the type parameter identifier.
+
+That means that if we make a type like this:
+
+```ts
+
+type Row<T> = {
+ value: T;
+ label: string;
+ orientation: 'vertical' | 'horizontal';
+};
+```
+
+A consumer of this type could pass literally _anything_ for Row. All of these would be valid:
+
+```ts
+type BooleanRow = Row<boolean>;
+type RegexRow = Row<RegExp>;
+type RowRowRowStringRow = Row<Row<Row<Row<string>>>>;
+type VoidFuncRow = Row<() => void>;
+```
+
+But our Row component is likely to not be written in such a way to handle _literally anything_ being passed in as a type. We need to set some static boundaries on what kinds of things are passed in for `T` to `Row`.
+
+_We need types for our types._
+
+Well. That's kinda what Generic type constraints are: _type constraints for your parameterized types_!
+
+It's a mouthful, but let's break it down step by step.
+
+## Using Generic Constraints
+
+So, let's say that our component is advanced enough to handle three things:
+
+- `string`: a row with a string value
+- `number`: a row with a numeric value
+- `() => string | number`: a row with a lazily evaluated value that can itself be a string or a number
+
+Let's make a type alias for our constraints:
+
+```ts
+type RowConstraints = string | number | (() => string | number);
+```
+
+> Note: Function type notation must be parenthesized when used in a union type (otherwise it might be ambiguous).
+
+To tell TypeScript that we only want to allow `Row` to accept types that fall into one of these categories we specified in `RowConstraints` we use the `extends` keyword.
+
+```ts
+type Row<T extends RowConstraints> = {
+ value: T;
+ label: string;
+ orientation: 'vertical' | 'horizontal';
+}
+```
+
+Now, if we try to use our `Row` generic with anything that doesn't match the above, TypeScript will report an error:
+
+<!-- TODO: twoslash error below -->
+
+```ts
+type StringArrayRow = Row<string[]>;
+// ^?
+```
+
+## Solving This Challenge
+
+Let the tests guide you on what specific constraints each type needs. By the end of this challenge, it should start to feel pretty robotic to add type constraints.
diff --git a/challenges/generic-type-constraints/solutions/1.ts b/challenges/generic-type-constraints/solutions/1.ts
new file mode 100644
index 00000000..c0b0959a
--- /dev/null
+++ b/challenges/generic-type-constraints/solutions/1.ts
@@ -0,0 +1,7 @@
+type AllowString<T extends string> = T;
+type AllowNumber<T extends number> = T;
+
+type CreateLogger<T extends (a: number) => void> = {
+ log: T;
+ exit: () => void;
+};
diff --git a/challenges/generic-type-constraints/tests.ts b/challenges/generic-type-constraints/tests.ts
new file mode 100644
index 00000000..a3fb7e8f
--- /dev/null
+++ b/challenges/generic-type-constraints/tests.ts
@@ -0,0 +1,42 @@
+import { Expect, Equal } from 'type-testing';
+
+type test_AllowStringString = Expect<Equal<
+ AllowString<string>,
+ string
+>>;
+
+// @ts-expect-error invalid input
+type error_AllowStringNumber = AllowString<number>;
+
+// @ts-expect-error invalid input
+type error_AllowStringBoolean = AllowString<boolean>;
+
+// @ts-expect-error invalid input
+type error_AllowNumberString = AllowNumber<string>;
+
+type test_AllowNumberNumber = Expect<Equal<
+ AllowNumber<number>,
+ number
+>>;
+
+// @ts-expect-error invalid input
+type error_AllowNumberBoolean = AllowNumber<boolean>;
+
+type test_CreateLogger = Expect<Equal<
+ CreateLogger<(a: number) => void>,
+ {
+ log: (a: number) => void;
+ exit: () => void;
+ }
+>>;
+
+// @ts-expect-error invalid input
+type error_CreateLoggerString = CreateLogger<string>;
+
+type error_CreateLoggerStringArg =
+ // @ts-expect-error invalid input
+ CreateLogger<(a: string) => void>;
+
+type error_CreateLoggerTwoArgs =
+ // @ts-expect-error invalid input
+ CreateLogger<(a: number, b: number) => void>;
\ No newline at end of file
diff --git a/challenges/generic-type-constraints/tsconfig.json b/challenges/generic-type-constraints/tsconfig.json
new file mode 100644
index 00000000..875cb600
--- /dev/null
+++ b/challenges/generic-type-constraints/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/challenges/generic-type-constraints/user.ts b/challenges/generic-type-constraints/user.ts
new file mode 100644
index 00000000..3f6817ec
--- /dev/null
+++ b/challenges/generic-type-constraints/user.ts
@@ -0,0 +1,4 @@
+type AllowString = unknown;
+type AllowNumber = unknown;
+
+type CreateLogger = unknown;
diff --git a/challenges/index-signatures/metadata.json b/challenges/index-signatures/metadata.json
new file mode 100644
index 00000000..b15def05
--- /dev/null
+++ b/challenges/index-signatures/metadata.json
@@ -0,0 +1,4 @@
+{
+ "id": "index-signatures",
+ "prerequisites": ["type-aliases", "primitive-data-types"]
+}
diff --git a/challenges/index-signatures/prompt.md b/challenges/index-signatures/prompt.md
new file mode 100644
index 00000000..e0e239fe
--- /dev/null
+++ b/challenges/index-signatures/prompt.md
@@ -0,0 +1,108 @@
+## When Index Signatures Save The Day
+
+It's common in any language to make general purpose mappings of one type to another type.
+
+Look at this theoretical API response from your company. This is a `/followerCountByUser` endpoint and we pass in some user we're looking
+
+```
+https://yourcompany.com/api/v1/followerCountByUser
+```
+
+```json
+{
+ "info": {
+ "count": 9001,
+ "currentPage": 1,
+ "pages": 22,
+ },
+ "results": {
+ "user_ddb04d2e-21ff-4c68-9bdc-135c16c8e74a": 0,
+ "user_1e118b25-c0b9-4bfc-8d04-901ad8a2eb20": 3,
+ "user_7c56283c-6a5e-4d79-bdd0-9c6a3cafd2c4": 15,
+ "user_2eac2f5e-4f11-4d36-84b5-9d273816d6f6": 7,
+ "user_4b88b4a3-8d42-4fc9-9f73-8db296d9b03d": 88,
+ "user_af836d5e-16a2-452d-bec4-694d6cd8e49f": 92,
+ "user_610c236f-b3bb-45e9-a09b-1d7e362c7fbb": 14,
+ "user_7a8e29f0-d7b0-4b75-9ad2-c8a145073eab": 6,
+ "user_eaa914df-4650-4c3b-9a04-723b5a63f297": 764,
+ "user_3199b7c6-7a8d-47eb-ae94-4e3457ad7760": 32,
+ // ... for many more rows in this page
+ },
+}
+```
+
+How would you write a type for your company's endpoint that returned data like this?
+
+In the real world you're going to have other things going on in types that might distract you. But don't get distracted by the pagination info. Let's zoom in on the `"results"` object.
+
+`results` seems to be some kind of mapping of user ids to a follower count. It's an object where they keys are (more or less) random strings and the values are all numbers.
+
+This turns out to be exactly the scenario for TypeScript index signatures!
+
+## How To Use Index Signatures
+
+In our case, here's how it looks:
+
+```ts
+type Results = {
+ [userId: string]: number;
+}
+```
+
+Let's really break this down piece by piece:
+
+- `type` starts a type declaration (we could also have used `interface` here).
+- `Results` is the name we're giving to this type.
+- `=` and `{` opens a new object type declaration.
+- `[` is the TypeScript syntax that says "hey, we're going to start defining a property name now".
+- `userId` is completely arbitrary. It's just a name that we picked. It has no impact on the resulting type.
+- `: string` this part indicates the type associated with this property\*.
+- `]` ends the property name declaration.
+- `: number` specifies that the type of values for this key are `number`.
+- `}` signals the end of the object type declaration.
+
+> \* By the way: a massively misunderstood fact about JavaScript has to do with object keys. JavaScript object keys can only be strings or symbols. _THAT'S IT_. _period_. No other data types are possible to store as object keys.
+>
+> Part of the reason this is so commonly misunderstood because you can index an object with a number, or a boolean, and actually more, and it will often work, which gives the wrong impression. JavaScript will _coerce_ anything you store as an object key to a string.
+>
+> Unfortunately (and widely seen as a small mistake in TypeScript's design) TypeScript actually allows setting numeric keys (so if you replaced `: string` with `: number` in the type above). This can give you the impression that you can set object keys as numbers, when in fact you cannot.
+>
+> Just watch out for this sneaky footgun in JavaScript.
+
+So wrapping it all up, our type for this API might look like this:
+
+```ts
+type Info = {
+ count: number;
+ currentPage: number;
+ pages: number;
+}
+
+type FollowerCountByUserResults = {
+ [userId: string]: number;
+}
+
+type FollowerCountByUser = {
+ info: Info;
+ results: FollowerCountByUserResults;
+}
+```
+
+Or, we could always inline everything (this works just fine with index signatures):
+
+```ts
+type FollowerCountByUser = {
+ info: {
+ count: number;
+ currentPage: number;
+ pages: number;
+ };
+ results: {
+ [userId: string]: number;
+ };
+};
+```
+
+## Solving This Challenge
+
+Take a look at the tests. You'll see some
\ No newline at end of file
diff --git a/challenges/index-signatures/solutions/1.ts b/challenges/index-signatures/solutions/1.ts
new file mode 100644
index 00000000..e5b5aa8d
--- /dev/null
+++ b/challenges/index-signatures/solutions/1.ts
@@ -0,0 +1,16 @@
+type GroceryList = {
+ [groceryItem: string]: number
+};
+
+type InnapropriateActionBySituation = {
+ [situation: string]: string[];
+}
+
+type CharactersById = {
+ [character: number]: {
+ id: number;
+ name: string;
+ status: string;
+ species: string;
+ }
+}
\ No newline at end of file
diff --git a/challenges/index-signatures/tests.ts b/challenges/index-signatures/tests.ts
new file mode 100644
index 00000000..b01111c1
--- /dev/null
+++ b/challenges/index-signatures/tests.ts
@@ -0,0 +1,59 @@
+const groceryList: GroceryList = {
+ carrots: 5,
+ potatoes: 12,
+ sweetPotatoes: 2,
+ turnips: 1,
+ parsnips: 1,
+ beets: 10,
+ radishes: 2,
+ rutabagas: 1,
+ onions: 3,
+ garlic: 2,
+
+ // @ts-expect-error intentionally invalid
+ shouldError: "because it's a string",
+
+ // @ts-expect-error intentionally invalid
+ shouldAlsoError: true
+};
+
+// note: these can change. I'm tired, haha. Maybe they're funny? Tomorrow will tell.
+const innapropriateActionBySituation: InnapropriateActionBySituation = {
+ funeral: ['excessive laughter', 'bringing up personal achievements'],
+ medicalDiagnosis: ['jokes about American healthcare', 'WebMD', 'doomscrolling twitter instead of listening'],
+ leetcodeInterview: ['praise of CSS', 'citing XKCD comics by number from memory', 'use of emojis in whiteboard exercises followed by pontificating about your deep knowledge of UTF-16'],
+ friendExperiencingHeartbreak: ['victory dance because you hated their S.O.', 'offers to turn on the 1999 cinematic masterpiece, The Mummy, with Brendan Fraser and Rachel Weisz'],
+};
+
+const charactersById: CharactersById = {
+ 1: {
+ id: 1,
+ name: "Rick Sanchez",
+ status: "Alive",
+ species: "Human",
+ },
+ 2: {
+ id: 2,
+ name: "Morty Smith",
+ status: "Alive",
+ species: "Human",
+ },
+ 3: {
+ id: 3,
+ name: "Summer Smith",
+ status: "Alive",
+ species: "Human",
+ },
+ 4: {
+ id: 4,
+ name: "Beth Smith",
+ status: "Alive",
+ species: "Human",
+ },
+ 5: {
+ id: 5,
+ name: "Jerry Smith",
+ status: "Alive",
+ species: "Human",
+ },
+};
diff --git a/challenges/index-signatures/tsconfig.json b/challenges/index-signatures/tsconfig.json
new file mode 100644
index 00000000..875cb600
--- /dev/null
+++ b/challenges/index-signatures/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/challenges/index-signatures/user.ts b/challenges/index-signatures/user.ts
new file mode 100644
index 00000000..7b2c3f19
--- /dev/null
+++ b/challenges/index-signatures/user.ts
@@ -0,0 +1,5 @@
+type GroceryList = unknown;
+
+type InnapropriateActionBySituation = unknown;
+
+type CharactersById = unknown
\ No newline at end of file
diff --git a/challenges/indexed-types/metadata.json b/challenges/indexed-types/metadata.json
new file mode 100644
index 00000000..1c5af0e7
--- /dev/null
+++ b/challenges/indexed-types/metadata.json
@@ -0,0 +1,4 @@
+{
+ "id": "indexed-types",
+ "prerequisites": ["primitive-types", "type-unions", "keyof", "literal-types"]
+}
diff --git a/challenges/indexed-types/prompt.md b/challenges/indexed-types/prompt.md
new file mode 100644
index 00000000..8531991c
--- /dev/null
+++ b/challenges/indexed-types/prompt.md
@@ -0,0 +1,97 @@
+## What Indexed Types Are For
+
+Indexed types allow you to look inside other types. They're a useful tool when accessing array/tuple values, object values, and more! We're going to see much more complicated uses for indexed types, but for this challenge, let's just focus on the basics.
+
+## How To Use Index Types
+
+### Arrays
+
+Just how you can use a number index to grab an element of an array:
+
+```ts
+const cars = ["Bugatti", "Ferarri", "Lambo", "Porsche", "Toyota Corolla"];
+const secondCar = cars[1];
+```
+
+You can do exactly the same thing with types;
+
+```ts
+type Cars = ["Bugatti", "Ferarri", "Lambo", "Porsche", "Toyota Corolla"];
+type SecondCar = Cars[1];
+// ^?
+```
+
+> Notice that TypeScript evaluates the literal value `"Ferarri"`. It's not just `string`!
+
+### Objects
+
+Same for objects:
+
+```ts
+const donations = {
+ "Bono": 15_000_000,
+ "J.K. Rowling": 160_000_000,
+ "Taylor Swift": 45_000_000,
+ "Elton John": 600_000_000,
+ "Angelina Jolie and Brad Pitt": 100_000_000,
+}
+const eltonDonations = donations["Elton John"];
+```
+
+and (you guessed it!) object types:
+
+```ts
+type Donations = {
+ "Bono": 15_000_000,
+ "J.K. Rowling": 160_000_000,
+ "Taylor Swift": 45_000_000,
+ "Elton John": 600_000_000,
+ "Angelina Jolie and Brad Pitt": 100_000_000,
+};
+
+type EltonDonations = Donations["Elton John"];
+// ^?
+```
+
+> Notice that TypeScript evaluates the literal value for Elton's donations. It's not just `number`!
+
+### Strings
+
+If you're getting excited that you might be able to do the same for strings, I have somewhat bad news for you, unfortunately.
+
+The following is valid TypeScript
+
+```ts
+const question = "Have the humans delivered their ultimate cup of coffee?";
+const firstCharacter = question[0];
+```
+
+And this is also valid:
+
+```ts
+type Question = "Have the humans delivered their ultimate cup of coffee?";
+type FirstCharacter = Question[0];
+// ^?
+```
+
+But perhaps you notice a difference from the above examples that returned a literal type. Here, with TypeScript strings, the resultant value is just `string` and not a more specific constant value like `H` (the first character of the string type). That means that while it's not a syntax error to index a string type, it also effectively _does nothing_ since it will always result in `string`.
+
+In fact, TypeScript doesn't even check (or care about) the specific value you index with. You'll always get back string:
+
+```ts
+type Empty = "";
+type IndexEmpty = Empty[9001];
+// ^?
+```
+
+Not a big deal or anything, but just something to be aware of in case you were expecting a different behavior.
+
+> _spoiler alert_: there actually _ARE_ ways to index a string and return a particular character, but ends up involving some quite advanced type machinery. Check out the [First Character](todo-first-character) challenge if you're curious.
+
+## Solving This Challenge
+
+This one should feel easy to pass. Let the tests guide you.
+
+And, remember, while this challenge is pretty straightforward to complete, we're soon going to be doing some pretty advanced work that relies heavily on indexed types.
+
+Onward!
diff --git a/challenges/indexed-types/solutions/1.ts b/challenges/indexed-types/solutions/1.ts
new file mode 100644
index 00000000..0a69189e
--- /dev/null
+++ b/challenges/indexed-types/solutions/1.ts
@@ -0,0 +1,2 @@
+type TheCoolestCarEverMade = Cars[5];
+type TruckDriverBonusGiver = Donations["Taylor Swift"];
diff --git a/challenges/indexed-types/tests.ts b/challenges/indexed-types/tests.ts
new file mode 100644
index 00000000..987a22d4
--- /dev/null
+++ b/challenges/indexed-types/tests.ts
@@ -0,0 +1,22 @@
+import { Expect, Equal } from 'type-testing';
+
+type Cars = ["Bugatti", "Ferarri", "Lambo", "Porsche", "Toyota Corolla"]
+
+type Donations = {
+ "Bono": 15_000_000,
+ "J.K. Rowling": 160_000_000,
+ "Taylor Swift": 45_000_000,
+ "Elton John": 600_000_000,
+ "Angelina Jolie and Brad Pitt": 100_000_000,
+};
+
+type test_TheCoolestCarEverMade = Expect<Equal<
+ TheCoolestCarEverMade,
+ "Toyota Corolla"
+>>;
+
+type test_TruckDriverBonusGiver = Expect<Equal<
+ TruckDriverBonusGiver,
+ "Taylor Swift"
+>>;
+
diff --git a/challenges/indexed-types/tsconfig.json b/challenges/indexed-types/tsconfig.json
new file mode 100644
index 00000000..875cb600
--- /dev/null
+++ b/challenges/indexed-types/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/challenges/indexed-types/user.ts b/challenges/indexed-types/user.ts
new file mode 100644
index 00000000..c26899d1
--- /dev/null
+++ b/challenges/indexed-types/user.ts
@@ -0,0 +1,2 @@
+type TheCoolestCarEverMade = unknown;
+type TruckDriverBonusGiver = unknown;
diff --git a/challenges/keyof/metadata.json b/challenges/keyof/metadata.json
new file mode 100644
index 00000000..0c9ef4c6
--- /dev/null
+++ b/challenges/keyof/metadata.json
@@ -0,0 +1,4 @@
+{
+ "id": "keyof",
+ "prerequisites": ["type-aliases", "literal-types", "type-unions"]
+}
diff --git a/challenges/keyof/prompt.md b/challenges/keyof/prompt.md
new file mode 100644
index 00000000..7d2ccfb8
--- /dev/null
+++ b/challenges/keyof/prompt.md
@@ -0,0 +1,73 @@
+## The Problem `keyof` solves
+
+The `keyof` operator is used for extracting a union representing the keys (also known as "properties") of a type.
+
+Let's say your audiophile cousin is asking you to digitize her casette tape collection (she's convinced they "sound better" on casette... yawn..). So you make an object where you count up how many albums you have for each artist:
+
+```ts
+const casettesByArtist = {
+ 'Alanis Morissette': 2,
+ 'Mariah Carey': 8,
+ 'Nirvana': 3,
+ 'Oasis': 2,
+ 'Radiohead': 3,
+ 'No Doubt': 3,
+ 'Backstreet Boys': 3,
+ 'Spice Girls': 2,
+ 'Green Day': 2,
+ 'Pearl Jam': 5,
+ 'Metallica': 5,
+ 'Guns N\' Roses': 2,
+ 'U2': 3,
+ 'Aerosmith': 4,
+ 'R.E.M.': 4,
+ 'Blur': 3,
+ 'The Smashing Pumpkins': 5,
+ 'Britney Spears': 3,
+ 'Whitney Houston': 3,
+};
+```
+
+But what if you wanted to extract all these keys as a type?
+
+We could always re-type all of them in a literal union:
+
+```ts
+type Artists = 'Alanis Morissette' | 'Mariah Carey' | 'Nirvana'
+ | 'Oasis' | 'Radiohead' | 'No Doubt'| 'Backstreet Boys'
+ | 'Spice Girls' | 'Green Day' | 'Pearl Jam'| 'Metallica'
+ | 'Guns N\' Roses' | 'U2' | 'Aerosmith' | 'R.E.M.' | 'Blur'
+ | 'The Smashing Pumpkins' | 'Britney Spears' | 'Whitney Houston'
+```
+
+But that's pretty Rough. You _certainly_ would not want to retype all those artist names. What if you forget one? What if you misspell one?
+
+Great news: you can use `keyof` to solve this problem!
+
+## How To Use `keyof`
+
+`keyof` is special TypeScript syntax that you use before any type.
+
+In our case we _don't have_ a type to start working with (because we), so we create one with the `typeof` operator:
+
+```ts
+type CasettesByArtist = typeof casettesByArtist;
+```
+
+Then we can use `keyof` on our new type to get an alias that represents the union of all keys in our `casettestByArtist` object.
+
+```ts
+type Artists = keyof CasettesByArtist;
+```
+
+## What `keyof` _returns_
+
+The result of `keyof` is always a union.
+
+> Even if there are 0 or 1 objects, it doesn't hurt to think of the result as a union. If there are no elements in the result will be `never` (which is the empty set in "Set theory" terminology). When there's only one key than the resulting type will be a single primitive or literal type.
+
+## Solving This Challenge
+
+We have a `getCasetteCount` function that should error if it's passed anything other than a valid artist name from your `casettesByArtist` object.
+
+Remember, we don't want to ever have to retype the keys in the `casettesByArtist` object.
diff --git a/challenges/keyof/solutions/1.ts b/challenges/keyof/solutions/1.ts
new file mode 100644
index 00000000..f571508f
--- /dev/null
+++ b/challenges/keyof/solutions/1.ts
@@ -0,0 +1 @@
+type Artist = keyof typeof casettesByArtist;
diff --git a/challenges/keyof/tests.ts b/challenges/keyof/tests.ts
new file mode 100644
index 00000000..f6ef279e
--- /dev/null
+++ b/challenges/keyof/tests.ts
@@ -0,0 +1,32 @@
+const casettesByArtist = {
+ 'Alanis Morissette': 2,
+ 'Mariah Carey': 8,
+ 'Nirvana': 3,
+ 'Oasis': 2,
+ 'Radiohead': 3,
+ 'No Doubt': 3,
+ 'Backstreet Boys': 3,
+ 'Spice Girls': 2,
+ 'Green Day': 2,
+ 'Pearl Jam': 5,
+ 'Metallica': 5,
+ 'Guns N\' Roses': 2,
+ 'U2': 3,
+ 'Aerosmith': 4,
+ 'R.E.M.': 4,
+ 'Blur': 3,
+ 'The Smashing Pumpkins': 5,
+ 'Britney Spears': 3,
+ 'Whitney Houston': 3,
+};
+
+const getCasetteCount = (artist: Artist) => {
+ return casettesByArtist[artist];
+}
+
+// should work just fine for a valid artist
+getCasetteCount('Mariah Carey');
+
+// should error for artists that are not part of the original
+// @ts-expect-error
+getCasetteCount('Red Hot Chili Peppers')
diff --git a/challenges/keyof/tsconfig.json b/challenges/keyof/tsconfig.json
new file mode 100644
index 00000000..875cb600
--- /dev/null
+++ b/challenges/keyof/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/challenges/keyof/user.ts b/challenges/keyof/user.ts
new file mode 100644
index 00000000..bc524566
--- /dev/null
+++ b/challenges/keyof/user.ts
@@ -0,0 +1 @@
+type Artist = unknown;
diff --git a/challenges/literal-types/metadata.json b/challenges/literal-types/metadata.json
new file mode 100644
index 00000000..423d9afe
--- /dev/null
+++ b/challenges/literal-types/metadata.json
@@ -0,0 +1,4 @@
+{
+ "id": "literal-types",
+ "prerequisites": ["primitive-data-types", "type-unions"]
+}
diff --git a/challenges/literal-types/prompt.md b/challenges/literal-types/prompt.md
new file mode 100644
index 00000000..fbc72bad
--- /dev/null
+++ b/challenges/literal-types/prompt.md
@@ -0,0 +1,81 @@
+## The Problem Literal Types Solve
+
+JavaScript, like most programming languages has a concept of [primitive data types](todo-primitive-data-types). Primitive data types are things like `string`, `boolean`, `number`, and `object`.
+
+> sidenote: in JavaScript, arrays and functions are actually objects, but that's a topic for another time :)
+
+But TypeScript isn't _like_ most programming languages. It's better. It takes takes things to the next level by introducing _literal_ data types.
+
+You can think of literal data types as being an infinite set of subsets of their primitive counterparts. For example
+
+### A Practical Use-Case
+
+Literal types can be used to create a rainbow of possibilities. In this case, we've defined a type `RainbowColor` that can only have one of the types specified in a union of literal strings.
+
+```ts
+type RainbowColor = 'red' | 'orange' | 'yellow' | 'green' | 'blue' | 'indigo' | 'violet';
+```
+
+Then, we can use this type in a function to ensure bad values are not passed in:
+
+```ts
+function pickColor(color: RainbowColor): void {
+ console.log(`I choose the color ${color}!`);
+}
+
+// no error: TypeScript is happy!
+pickColor('yellow');
+
+// Error: Argument of type 'purple' is not assignable to parameter of type 'RainbowColor'.
+pickColor('purple');
+// ^?
+```
+
+> By the way. Did you know that purple's not in the rainbow because [there's no "purple" wavelength of light](https://www.youtube.com/results?search_query=purple+is+not+a+color). It's true. Our brains fabricate it for us to make sense of paradoxical visual inputs.
+
+### Literal Types For Returns
+
+But wait! There's A LOT more! Literal types are useful for returns, too. Check out this code:
+
+```ts
+type Day = 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday' | 'Sunday';
+
+const isItPartyTime = (day: Day) => {
+ switch (day) {
+ case 'Friday':
+ case 'Saturday':
+ case 'Sunday':
+ return 'definitely party time';
+
+ default:
+ return 'prolly lay low for now'
+ }
+}
+
+isItPartyTime('Monday');
+// ^?
+```
+
+> /* the above example assumes a 4 day workweek since 4 day workweeks are observed to increase employee productivity.
+
+The _return type_ for this function is _also_ a literal type union. Notice that you didn't have to specify the return type anywhere. It just _works_ this way in TypeScript. Nice.
+
+### Why Are Type Literals Even Necessary?
+
+If you're thinking to yourself:
+
+> Why are type literals even necessary?  Lots of languages don't have anything like this and they seem to get along just fine with primitive types like `string` and `number` and `boolean`.
+
+The TLDR; is: once you pair type unions with literals, you can start _descriminating_ inputs based on one particular literal instance of a type versus another, TypeScript suddenly becomes capable of doing some pretty amazing static analysis on your code that you could never do if all you had were primitive types. If that's unpalatable to you, there's always COBOL. Try that out instead maybe?
+
+## Solving this Challenge
+
+In this prompt we talked mostly about string literals, but there are more kinds:
+
+- number literals
+ - (including fractional numbers)
+- boolean literals
+- function literals
+- object literals
+
+Take a look at the tests and see if you can create some type literals that will satisfy the tests.
diff --git a/challenges/literal-types/solutions/1.ts b/challenges/literal-types/solutions/1.ts
new file mode 100644
index 00000000..6f4775b5
--- /dev/null
+++ b/challenges/literal-types/solutions/1.ts
@@ -0,0 +1,21 @@
+type LiteralString = 'chocolate chips';
+type LiteralTrue = true;
+type LiteralNumbers = 1 | 2 | 3 | 4 | 5 | 6;
+type LiteralObject = {
+ name: 'chocolate chips',
+ inStock: true,
+ kilograms: 5,
+};
+type LiteralFunction = (a: number, b: number) => number;
+
+const literalString = 'Ziltoid the Omniscient';
+const literalTrue = true;
+const literalNumber = Math.random() > 0.5 ? 1 : 2;
+const almostPi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019891337
+const literalObject = {
+ origin: "far across the omniverse",
+ command: "fetch",
+ item: "the universe's ultimate cup of coffee (black)",
+ time: "five Earth minutes"
+};
+const literalFunction = (a: number, b: string) => a || b;
diff --git a/challenges/literal-types/tests.ts b/challenges/literal-types/tests.ts
new file mode 100644
index 00000000..4eaf7b94
--- /dev/null
+++ b/challenges/literal-types/tests.ts
@@ -0,0 +1,65 @@
+import { Expect, Equal } from 'type-testing';
+
+type test_LiteralString = Expect<Equal<
+ LiteralString,
+ 'chocolate chips'
+>>;
+
+type test_LiteralTrue = Expect<Equal<
+ LiteralTrue,
+ true
+>>;
+
+type test_LiteralNumber = Expect<Equal<
+ LiteralNumbers,
+ 1 | 2 | 3 | 4 | 5 | 6
+>>;
+
+type test_LiteralObject = Expect<Equal<
+ LiteralObject,
+ {
+ name: 'chocolate chips',
+ inStock: true,
+ kilograms: 5,
+ }
+>>;
+
+type test_LiteralFunction = Expect<Equal<
+ LiteralFunction,
+ (a: number, b: number) => number
+>>;
+
+type test_literalString = Expect<Equal<
+ typeof literalString,
+ 'Ziltoid the Omniscient'
+>>;
+
+type test_literalTrue = Expect<Equal<
+ typeof literalTrue,
+ true
+>>;
+
+type test_literalNumber = Expect<Equal<
+ typeof literalNumber,
+ 1 | 2
+>>;
+
+type test_almostPi = Expect<Equal<
+ typeof almostPi,
+ 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019891337
+>>;
+
+type test_literalObject = Expect<Equal<
+ typeof literalObject,
+ {
+ origin: "far across the omniverse",
+ command: "fetch",
+ item: "the universe's ultimate cup of coffee (black)",
+ time: "five Earth minutes"
+ }
+>>;
+
+type test_literalFunction = Expect<Equal<
+ typeof literalFunction,
+ (a: number, b: string) => string | number
+>>;
diff --git a/challenges/literal-types/tsconfig.json b/challenges/literal-types/tsconfig.json
new file mode 100644
index 00000000..875cb600
--- /dev/null
+++ b/challenges/literal-types/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/challenges/literal-types/user.ts b/challenges/literal-types/user.ts
new file mode 100644
index 00000000..8cd76b25
--- /dev/null
+++ b/challenges/literal-types/user.ts
@@ -0,0 +1,11 @@
+type LiteralString = unknown;
+type LiteralTrue = unknown;
+type LiteralNumbers = unknown;
+type LiteralObject = {};
+type LiteralFunction = unknown;
+
+const literalString = undefined;
+const literalTrue = undefined;
+const literalNumber = Math.random() > 0.5 ? undefined : undefined;
+const literalObject = {};
+const literalFunction = () => {}
\ No newline at end of file
diff --git a/challenges/mapped-object-types/metadata.json b/challenges/mapped-object-types/metadata.json
new file mode 100644
index 00000000..f527970e
--- /dev/null
+++ b/challenges/mapped-object-types/metadata.json
@@ -0,0 +1,4 @@
+{
+ "id": "mapped-object-types",
+ "prerequisites": ["index-signatures", "keyof", "generic-type-arguments", "indexed-types"]
+}
diff --git a/challenges/mapped-object-types/prompt.md b/challenges/mapped-object-types/prompt.md
new file mode 100644
index 00000000..831eea27
--- /dev/null
+++ b/challenges/mapped-object-types/prompt.md
@@ -0,0 +1,79 @@
+## Why Mapped Object Types Are Useful
+
+In mathematics, a "map" is a function that associates each element in one set with an element. That's where we get this usage of the word in computer science.
+
+Mapped types are one of the most potent and versatile features of TypeScript. They enable you to create new types by transforming the properties of existing types, making your code more robust, flexible, and maintainable. As you further your journey with TypeScript, you're going to find yourself reaching for mapped types pretty often to solve daily-living type (and data) transformation tasks.
+
+## How To Use Mapped Types
+
+It might seem a little strange, but let's start with a mapped type that _does nothing_. Here's how it looks:
+
+```ts
+type MoviesByGenre = {
+ action: 'Die Hard';
+ comedy: 'Groundhog Day';
+ sciFi: 'Blade Runner';
+ fantasy: 'The Lord of the Rings: The Fellowship of the Ring';
+ drama: 'The Shawshank Redemption';
+ horror: 'The Shining';
+ romance: 'Titanic';
+ animation: 'Toy Story';
+ thriller: 'The Silence of the Lambs';
+};
+
+type MovieInfoByGenre<T> = {
+ [K in keyof T]: T[K];
+};
+
+type Example = MovieInfoByGenre<MoviesByGenre>;
+```
+
+Let's talk about what this syntax does, piece by piece:
+
+- `type` begins a type declaration.
+- `MovieInfoByGenre` is the name we gave to our type
+- `<T>` defines generic parameter we named `T`
+- `= {` begins our type
+- `[` starts an index signature
+- `K` is the name we're giving to the value in this index signature.
+ - `K` (for "Key") and `P` (for "Property") are very common names to use in this particular situation. While it's not often the best choice, you'll see it around (including in TypeScript's own builtin types), so it's worthwhile to just roll with it if you see it. If you can make a more descriptive name, you should.
+- `in` is a special TypeScript operator for mapping. It tells TypeScript that `K` represents a single item in a larger set of things defined on the right side of the `in` operator.
+- `keyof T` is a union of all the keys of the `T` object.
+- `: T[K]` is regular type indexing. The value, `K`, can here be thought of as a singular property in a sort of loop. We take some individual value of `K` (which are keys of `T`) and then index `T` with that key, thereby producing a value that matches the value in `T` for that `K`.
+- `;` it might at first seem strange, but if you take a step back, this is just a `property: value` line in an object type, so we end it with a semicolon like we normally would with types in TypeScript.
+- `};` ends the type declaration.
+
+But, all this _stuff_ but we end up with a type that's literally identical to what we started with. In the above code, `Example` and `MoviesByGenre` are literally the same type to TypeScript because TypeScript is a structural type system. THey have all the same properties and values, so to TypeScript they are basically aliases at this point (aliases with extra steps, granted!).
+
+### Resetting all values
+
+So let's do the simplest possible thing to change our `Example` type. Let's just change one little part of the above:
+
+```diff
+type MovieInfoByGenre<T> = {
+- [K in keyof T]: T[K];
++ [K in keyof T]: boolean;
+};
+```
+
+Can you picture what our `Example` type would be if we made this change?
+
+It would look like this:
+
+```ts
+type Example = {
+ action: boolean;
+ comedy: boolean;
+ sciFi: boolean;
+ fantasy: boolean;
+ drama: boolean;
+ horror: boolean;
+ romance: boolean;
+ animation: boolean;
+ thriller: boolean;
+};
+```
+
+## Solving This Challenge
+
+The tests define a slightly more complicated remapping, but you actually have all the tools you need to make it work. Just take it slow and follow the syntax piece by piece if you get lost.
diff --git a/challenges/mapped-object-types/solutions/1.ts b/challenges/mapped-object-types/solutions/1.ts
new file mode 100644
index 00000000..e172ed5b
--- /dev/null
+++ b/challenges/mapped-object-types/solutions/1.ts
@@ -0,0 +1,7 @@
+type MovieInfoByGenre<T> = {
+ [K in keyof T]: {
+ name: string;
+ year: number;
+ director: string;
+ };
+};
diff --git a/challenges/mapped-object-types/tests.ts b/challenges/mapped-object-types/tests.ts
new file mode 100644
index 00000000..f1605829
--- /dev/null
+++ b/challenges/mapped-object-types/tests.ts
@@ -0,0 +1,61 @@
+type MoviesByGenre = {
+ action: 'Die Hard';
+ comedy: 'Groundhog Day';
+ sciFi: 'Blade Runner';
+ fantasy: 'The Lord of the Rings: The Fellowship of the Ring';
+ drama: 'The Shawshank Redemption';
+ horror: 'The Shining';
+ romance: 'Titanic';
+ animation: 'Toy Story';
+ thriller: 'The Silence of the Lambs';
+};
+
+type Example = MovieInfoByGenre<MoviesByGenre>;
+
+const example: Example = {
+ action: {
+ name: 'Die Hard',
+ year: 1988,
+ director: 'John McTiernan',
+ },
+ comedy: {
+ name: 'Groundhog Day',
+ year: 1993,
+ director: 'Harold Ramis',
+ },
+ sciFi: {
+ name: 'Blade Runner',
+ year: 1982,
+ director: 'Ridley Scott',
+ },
+ fantasy: {
+ name: 'The Lord of the Rings: The Fellowship of the Ring',
+ year: 2001,
+ director: 'Peter Jackson',
+ },
+ drama: {
+ name: 'The Shawshank Redemption',
+ year: 1994,
+ director: 'Frank Darabont',
+ },
+ horror: {
+ name: 'The Shining',
+ year: 1980,
+ director: 'Stanley Kubrick',
+ },
+ romance: {
+ name: 'Titanic',
+ year: 1997,
+ director: 'James Cameron',
+ },
+ animation: {
+ name: 'Toy Story',
+ year: 1995,
+ director: 'John Lasseter',
+ },
+ thriller: {
+ name: 'The Silence of the Lambs',
+ year: 1991,
+ director: 'Jonathan Demme',
+ },
+};
diff --git a/challenges/mapped-object-types/tsconfig.json b/challenges/mapped-object-types/tsconfig.json
new file mode 100644
index 00000000..875cb600
--- /dev/null
+++ b/challenges/mapped-object-types/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/challenges/mapped-object-types/user.ts b/challenges/mapped-object-types/user.ts
new file mode 100644
index 00000000..a52b159c
--- /dev/null
+++ b/challenges/mapped-object-types/user.ts
@@ -0,0 +1 @@
+type MovieInfoByGenre = unknown
diff --git a/challenges/notes to dimitri.md b/challenges/notes to dimitri.md
new file mode 100644
index 00000000..8da78d36
--- /dev/null
+++ b/challenges/notes to dimitri.md
@@ -0,0 +1,161 @@
+## ideas for future challenges (in no particular order)
+
+- unique-symbol
+- functions-with-literal-returns
+- curly-curly
+- lowercase-o-object
+- never
+ - unions-with-never
+ - intersections-with-never
+- unknown
+ - unions-with-unknown
+ - intersections-with-unknown
+- any
+ - unions-with-any
+ - intersections-with-any
+- type-guards (continuing on from type unions)
+- compound-string-literals
+- mapping-arrays
+- array-item-type
+- as-const
+- generic-function-arguments
+- generic-function-constraints
+- generic-type-defaults
+- tuples
+- tuple-labels
+- typeof
+- indexing-types
+- mapping-modifiers https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#mapping-modifiers
+- key-remapping-with-as https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#key-remapping-via-as
+
+## TODO
+
+- figure out patching `Pick` out (`noLib`?)
+- JSON Schema for metadata.json
+- add some kind of tags system to metadata
+
+
+## random disorganized snippets for later
+
+
+
+
+
+
+
+
+a good one for strong generics
+
+```ts
+const config = {
+ apiUrl: 'https://api.example.com',
+ apiKey: 'your-api-key',
+} as const;
+
+function getConfigValue<K extends keyof typeof config>(key: K) {
+ return config[key];
+}
+
+const apiUrl = getConfigValue('apiUrl');
+```
+
+
+
+
+
+
+
+### Universe 2: with functions
+
+Functions can also take generic _type arguments_ along with their regular JavaScript-land arguments.
+
+```ts
+const createRow = <T>(row: {
+ label: string;
+ value: T;
+ disabled: boolean;
+}) => {
+ // ... do things
+}
+```
+
+This syntax might look a little funky at first, but if you stand back and squint a bit, you'll see that it's just a mashup of the regular argument syntax and the type generic syntax we saw above.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+const characters = {generic-constraints
+ ironMan: {
+ name: 'Tony Stark',
+ age: 53,
+ attributes: ['genius', 'billionaire', 'playboy', 'philanthropist']
+ },
+ thor: {
+ name: 'Thor Odinson',
+ age: 1500,
+ attributes: ['Asgardian', 'God', 'thunder'],
+ },
+ hulk: {
+ name: 'Bruce Banner',
+ age: 44,
+ attributes: ['gamma-irradiated', 'scientist']
+ },
+ captainAmerica: {
+ name: 'Steve Rogers',
+ age: 105,
+ attributes: ['super-soldier', 'strong'],
+ },
+ blackWidow: {
+ name: 'Natasha Romanoff',
+ age: 34,
+ attributes: ['master spy', 'martial artist'],
+ },
+ spiderMan: {
+ name: 'Peter Parker',
+ age: 19,
+ attributes: ['agile', 'web-slinging'],
+ },
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+type StarWarsCharacter = {
+ [id: string]: {
+ fullName: string;
+ species: string;
+ // ...imagine many more properties
+ }
+};
+
+const starWarsCharacters: StarWarsCharacter = {
+ luke: { fullName: "Luke Skywalker", species: "Human" },
+ yoda: { fullName: "Yoda", species: "Unknown" },
+ chewy: { fullName: "Chewbacca", species: "Wookiee" },
+ // ...imagine many more characters
+};
+
+type SpeciesByCharacterId<T extends StarWarsCharacter> = {
+ [Id in keyof T]: T[Id]["species"]
+};
\ No newline at end of file
diff --git a/challenges/pick/metadata.json b/challenges/pick/metadata.json
new file mode 100644
index 00000000..dd3eb14f
--- /dev/null
+++ b/challenges/pick/metadata.json
@@ -0,0 +1,4 @@
+{
+ "id": "pick",
+ "prerequisites": ["literal-types", "keyof", "mapped-object-types", "generic-type-constraints"]
+}
diff --git a/challenges/pick/prompt.md b/challenges/pick/prompt.md
new file mode 100644
index 00000000..a177b506
--- /dev/null
+++ b/challenges/pick/prompt.md
@@ -0,0 +1,149 @@
+## The Problem `Pick` Solves
+
+`Pick` is a very useful helper type that allows you to create a type by using an existing type as a starting point.
+
+Say, for example, your codebase has a type that looks like this:
+
+```ts
+interface Pokemon {
+ name: string;
+ type: string;
+ hitPoints: number;
+ stage: string;
+ evolutionStage: number;
+ attacks: string[];
+ weakness: string;
+ resilience: string;
+}
+```
+
+That's a lot of properties! But what if you have a function that only needs two properties from this type:
+
+```ts
+const pickYourPokemon = (pokemon: Pokemon) => {
+ const { type, name } = pokemon;
+
+ return `You picked the ${type}-type Pokemon ${name}!`
+}
+```
+
+You would call your function like this:
+
+```ts
+const pikachu = {
+ name: 'Pikachu',
+ type: 'Electric',
+}
+console.log(pickYourPokemon(pikachu))
+// ^------ oops! There's a type-error here!
+
+```
+
+But now there's a type error because you didn't provide the full `Pokemon` type.
+
+As you can see, this function requires the full `Pokemon` type, even though your function only actually uses half of properties of the full `Pokemon` type.
+
+How can you make this easier?
+
+### Exploring Your Options
+
+You could always hardcode the object directly into the function
+
+```diff
+- const pickYourPokemon = (pokemon: Pokemon) => {
++ const pickYourPokemon = (pokemon: { name: string, type: string }) => {
+```
+
+You might also be tempted to separate all the things you need into two positional arguments.
+
+```diff
+- const pickYourPokemon = (pokemon: Pokemon) => {
++ const pickYourPokemon = (name: string, type: string) => {
+```
+
+But there's a much better way! You can use the `Pick` utility type! You simply to provide the keys you want from the original type and it produces a new type for your specific use-case.
+
+This is great news because it means:
+
+1. Any time something in the base `Pokemon` type changes, it'll also be updated in your function. If you hardcoded, they'd fall out of sync.
+1. You don't have to repeat yourself!
+1. You are communicating to future readers that your function is using a subset of the types from `Pokemon`.
+1. Consumers of your `pickYourPokemon` function don't need to provide data the function doesn't even use (that would be annoying, wouldn't it?).
+
+## How To Use `Pick`
+
+`Pick` is a special _built-in_ TypeScript type that's always in scope, so you don't need to import it from anywhere. You can just use it as-if it was already imported.
+
+To use it, you must provide `Pick` with two things:
+
+1. The type original object you're basing your new type on (in our example, `Pokemon`)
+1. A _union_ of strings representing all the keys you wish to pick from the base type (in our case, `name` and `type`).
+
+Let's talk about the `union` part real quick. TypeScript has a special syntax that represent an unordered unique set of values. You separate them with the "pipe" character.
+
+In our example, we have a union of strings. It looks like this:
+
+```ts
+type BasicPokemonKeys = 'name' | 'type';
+```
+
+Then we can use this type with `Pick` and our `Pokemon` base type:
+
+```ts
+type BasicPokemonInfo = Pick<Pokemon, BasicPokemonKeys>
+```
+
+We're almost there!
+
+A few things about your options fo the syntax here. We made the `BasicPokemonKeys` helper type, but we didn't have to. We can declare the type _inline_ like this:
+
+```ts
+type BasicPokemonInfo = Pick<Pokemon, 'name' | 'type'>
+```
+
+Then, we can use this new type in our function definition:
+
+```diff
+- const pickYourPokemon = (pokemon: Pokemon) => {
++ const pickYourPokemon = (pokemon: BasicPokemonInfo) => {
+```
+
+Just like we inlined the keys, we could also inline the entire `Pick` itself. In fact, this style is what you'll most often see in TypeScript codebases in a situation like this. Here's a full example:
+
+```ts
+interface Pokemon {
+ name: string;
+ type: string;
+ hitPoints: number;
+ stage: string;
+ evolutionStage: number;
+ attacks: string[];
+ weakness: string;
+ resilience: string;
+}
+
+const pickYourPokemon = (
+ pokemon: Pick<Pokemon, 'name' | 'type'>
+) => {
+ const { type, name } = pokemon;
+ return `You picked the ${type}-type Pokemon ${name}!`
+}
+
+const pikachu = {
+ name: 'Pikachu',
+ type: 'Electric',
+}
+
+console.log(pickYourPokemon(pikachu))
+// => `You picked the Electric-type Pokemon Pikachu!
+```
+
+## Solving This Challenge
+
+In this challenge you'll implement the `Pick` type described above.
+
+Remember that the TypeScript `keyof` operator is the way of getting the keys of a type. So `keyof Pokemon` will result in a union of strings that looks like `'name' | 'type' ...... | 'weakness' | 'resilience'`. If `Pick` didn't take
+
+By convention, the first argument of the `Pick` type is the base type (so, `Pokemon` in our example) and the second generic argument is a union of strings of that are valid keys of the base type.
+
+Another convention is the use of `T` and `K` as parameter types. For extremely generic types like `Pick` this is normal. As your types become more specific you should try to make more descriptive names.
diff --git a/challenges/pick/solutions/1.ts b/challenges/pick/solutions/1.ts
new file mode 100644
index 00000000..3b3456d8
--- /dev/null
+++ b/challenges/pick/solutions/1.ts
@@ -0,0 +1,8 @@
+/**
+ * From T, pick a set of properties whose keys are in the union K
+ *
+ * This solution is verbatim from the ES5 builtins.
+ */
+type Pick<T, K extends keyof T> = {
+ [P in K]: T[P];
+};
diff --git a/challenges/pick/tests.ts b/challenges/pick/tests.ts
new file mode 100644
index 00000000..4d0adf12
--- /dev/null
+++ b/challenges/pick/tests.ts
@@ -0,0 +1,38 @@
+interface Pokemon {
+ name: string;
+ type: string;
+ hitPoints: number;
+ stage: string;
+ evolutionStage: number;
+ attacks: string[];
+ weakness: string;
+ resilience: string;
+}
+
+const pickYourPokemon = (
+ pokemon: Pick<Pokemon, 'name' | 'type'>
+) => {
+ const { type, name } = pokemon;
+ return `You picked the ${type}-type Pokemon ${name}!`
+}
+
+const pikachu = {
+ name: 'Pikachu',
+ type: 'Electric',
+}
+
+console.log(pickYourPokemon(pikachu))
+// => `You picked the Electric-type Pokemon Pikachu!`
+
+/** Selecting an invalid property should be an error. */
+const pokemonAttacks = (
+ // @ts-expect-error
+ pokemon: Pick<Pokemon, 'attacks' | 'age'>
+) => {
+ return 'Oops! WE ';
+}
+
+/** It's also totally fine to select a single property */
+const recallPokemon = (pokemon: Pick<Pokemon, 'name'>) => {
+ return `You recalled ${pokemon.name}!`
+}
\ No newline at end of file
diff --git a/challenges/pick/tsconfig.json b/challenges/pick/tsconfig.json
new file mode 100644
index 00000000..875cb600
--- /dev/null
+++ b/challenges/pick/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/challenges/pick/user.ts b/challenges/pick/user.ts
new file mode 100644
index 00000000..29b2e6ba
--- /dev/null
+++ b/challenges/pick/user.ts
@@ -0,0 +1 @@
+type Pick<T, K> = unknown;
\ No newline at end of file
diff --git a/challenges/primitive-data-types/metadata.json b/challenges/primitive-data-types/metadata.json
new file mode 100644
index 00000000..bcb0ea51
--- /dev/null
+++ b/challenges/primitive-data-types/metadata.json
@@ -0,0 +1,4 @@
+{
+ "id": "primitive-data-types",
+ "prerequisites": []
+}
diff --git a/challenges/primitive-data-types/prompt.md b/challenges/primitive-data-types/prompt.md
new file mode 100644
index 00000000..69f81ddf
--- /dev/null
+++ b/challenges/primitive-data-types/prompt.md
@@ -0,0 +1,54 @@
+## The Problem Primitive Data Types Solve
+
+Because the ability to create primitive types are the foundational idea behind TypeScript, asking what problem primitive types solve is more like asking "what problem does _TypeScript_ solve".
+
+TypeScript is like a really really smart spellchecker. It helps you work faster when you're at your best, but it also saves you from misspelling words when you're under stress at 3am the night before a big term paper is due.
+
+Think about it for a second: spellcheckers work because there are encoded with rules about the vocabulary and syntax of English. Similarly, TypeScript has advanced knowledge about the vocabulary and syntax of JavaScript. But TypeScript can do even better because you can specify the type of your data. That allows TypeScript to make even better judgement calls about whether something you're trying to do is likely to be a bug (or not).
+
+## What Does "Primitive" mean in this context?
+
+And speaking of words and language, the usage of "primitive" in this sense is a bit of technical jargon. If you look up "primitive" in the dictionary you'll find that the top definition is:
+
+> 1. relating to, denoting, or preserving the character of an early stage in the evolutionary or historical development of something.
+
+So basically, it means "ancient" or "undeveloped"? huh???
+
+Nope. That's actually not the way the word is used in this context. If you keep reading down the list, you'll find a less common definition:
+
+> 3. not developed or derived from anything else.
+
+Ahhh. Yes. That one makes more sense. That's what primitive types are. They are the base units of information from which everything else is derived.
+
+Indeed, all TypeScript types are derived from primitive types (aside from a few very very rare exceptions most people are not even aware of\*).
+
+> \* if you're incredibly curious: a very short list of exceptions that the compiler has special knowledge of do exist. E.g. usages `intrinsic` keyword and `ThisType`.
+
+## What Do Primitive Types Look Like
+
+It's a bit confusing at first, but primitive types are defined with _lowercase_ letters.
+
+Here are some of the basic types:
+
+- `number`: since JavaScript only has one real number type (IEEE-754 64-bit floating point numbers), so too does TypeScript then not define types like `short` and `long` or types like `uint32` or `uint16` like you might be used to in other languages. Instead we just use `number` for everything.
+- `string`: a variable length set of characters (UTF-16).
+- `boolean`: Don't let this next sentence keep you up at night if it sounds strange, but just keep in the back of your mind that boolean isn't actually a primitive type deep down in TypeScript internals. It's a little different from string or number since it is just an alias for the union of `true` and `false`. It doesn't _widen_ like `number` and `string` do, and thus is slightly inconsistent. If that didn't make sense to you right now don't worry. This problem almost never surfaces in a way that's problematic so you're clear to just consider it a primitive type. Also, the way TypeScript handles `boolean` is actually the more correct way to model things from a ["Set theory"](https://en.wikipedia.org/wiki/Set_theory) standpoint.
+- `null`: this is technically really a "literal type", but it refers to the type of the `null` value in JavaScript. Since `null` is special, it get's its own type.
+- `undefined`: same as with `null`. This is a specific JavaScript value and it has a corresponding TypeScript type.
+
+Then we've got some more advanced ones that you don't need to worry about quite yet. But here they are as a teaser:
+
+- `symbol`
+- `bigint`
+- `object`
+- `never`
+- `unknown`
+- `any`
+
+And while we're in the weeds for a moment, you should be aware that _capitalized_ variants of these things do actually exist: `Number`, `String`, `Boolean`, `Symbol`, `Object`. But these refer to something quite different (i.e. JavaScript global objects) and should virtually never be used as types.
+
+## Solving This Challenge
+
+To solve this challenge: add primitive types to the code until the errors go away.
+
+You might need to add type annotations to variables (declared with `const` or types of arguments). You might also need to add missing properties to objects.
diff --git a/challenges/primitive-data-types/solutions/1.ts b/challenges/primitive-data-types/solutions/1.ts
new file mode 100644
index 00000000..b00ee01c
--- /dev/null
+++ b/challenges/primitive-data-types/solutions/1.ts
@@ -0,0 +1,30 @@
+const playSong = (
+ name: string,
+ year: number,
+) => {
+ return `${name} was released in the year ${year}`;
+};
+
+const name: string = 'Frank Zappa';
+
+const age: number = 52;
+
+interface Musician {
+ name: string;
+ age: number;
+ deceased: boolean;
+}
+
+const musicianInfo = ({
+ name,
+ age,
+ deceased,
+}: Musician) => {
+ return `${name}, age ${age}${deceased ? ' (deceased)' : ''}`;
+};
+
+musicianInfo({
+ name,
+ age,
+ deceased: true,
+});
diff --git a/challenges/primitive-data-types/tests.ts b/challenges/primitive-data-types/tests.ts
new file mode 100644
index 00000000..7d2b6da5
--- /dev/null
+++ b/challenges/primitive-data-types/tests.ts
@@ -0,0 +1,10 @@
+import { Expect } from 'type-testing';
+
+type test_age = Expect<NotLiteral<number, typeof age>>;
+type test_name = Expect<NotLiteral<string, typeof name>>;
+
+/** this is just a helper type to sus out literals */
+type NotLiteral<T, U> =
+ 1 extends (T extends U ? U extends T ? 1 : 2 : 3)
+ ? true
+ : false
\ No newline at end of file
diff --git a/challenges/primitive-data-types/tsconfig.json b/challenges/primitive-data-types/tsconfig.json
new file mode 100644
index 00000000..875cb600
--- /dev/null
+++ b/challenges/primitive-data-types/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/challenges/primitive-data-types/user.ts b/challenges/primitive-data-types/user.ts
new file mode 100644
index 00000000..3774e70a
--- /dev/null
+++ b/challenges/primitive-data-types/user.ts
@@ -0,0 +1,29 @@
+const playSong = (
+ name,
+ year,
+) => {
+ return `${name} was released in the year ${year}`;
+};
+
+const name = 'Frank Zappa';
+
+const age = 52;
+
+interface Musician {
+ name: string;
+ age: number;
+ deceased: boolean;
+}
+
+const musicianInfo = ({
+ name,
+ age,
+ deceased,
+}: Musician) => {
+ return `${name}, age ${age}${deceased ? ' (deceased)' : ''}`;
+};
+
+musicianInfo({
+ name,
+ age,
+});
\ No newline at end of file
diff --git a/challenges/type-aliases/metadata.json b/challenges/type-aliases/metadata.json
new file mode 100644
index 00000000..041776bb
--- /dev/null
+++ b/challenges/type-aliases/metadata.json
@@ -0,0 +1,4 @@
+{
+ "id": "type-aliases",
+ "prerequisites": ["primitive-data-types"]
+}
diff --git a/challenges/type-aliases/prompt.md b/challenges/type-aliases/prompt.md
new file mode 100644
index 00000000..484536df
--- /dev/null
+++ b/challenges/type-aliases/prompt.md
@@ -0,0 +1,90 @@
+## What Problem Do Type Aliases Solve?
+
+![mars_climate_orbiter](https://www.simscale.com/wp-content/uploads/2017/12/Mars_Climate_Orbiter_768.jpg)
+
+Did you know that a 125 _million_ dollar robotic space probe, the Mars Climate Orbiter, crashed into Mars because of a simple units conversion.
+
+Let's envision that code in TypeScript and see how type aliases can help.
+
+```ts
+/**
+ * calculates landing thrusters based on distance from landing site
+ */
+const landSpacecraft = (distance: number) => {
+ // ... do fancy math here
+}
+```
+
+In this case, wouldn't it be nice if we could use a type that's more specific than `number`?
+
+Well.. We can!
+
+Here's how it looks:
+
+```ts
+/** International System of Units Meter */
+type Meters = number;
+
+const landSpacecraft = (distance: Meters) => {
+ // ... do fancy math here
+}
+```
+
+Cool, huh? Now we can do fun stuff like adding JSDoc (as you see above) that way people will see more information about how this type is intended to be _used_ in programs.
+
+## The Biggest Source Of Bugs With Aliases
+
+But unfortunately, this particular TypeScript types design might not be a great choice for such a job because the actual behavior may be surprising to you. You might expect the following code to have a type error, but it doesn't:
+
+```ts
+/** In */
+type Miles = number;
+
+const targetDistance: Miles = 100;
+
+landSpacecraft(targetDistance);
+```
+
+Wait! What's going on? `landSpacecraft` specifically asked for `Meters` but clearly we passed in `Miles` here. Our spacecraft is going to crash!
+
+Be careful that you understand that TypeScript is a _structural type system_. One result of this is that primitive types are _not_ something known as ["opaque types"](https://en.wikipedia.org/wiki/Opaque_data_type). To TypeScript, everything that's an alias for a number is still a number.
+
+There actually is a idiomatic TypeScript way to design this, but it requires another concept covered in another challenge [`type-unions`](TODO-link).
+
+## How To Create Type Aliases
+
+To create a new type alias you simply use the `type` TypeScript keyword followed by a space, then the name of your type (usually beginning with a capital letter), another space, an equals sign, a final space and then the _stuff_ you want to alias.
+
+```ts
+type MyAlias = number;
+```
+
+It's most common (but not mandatory) to use a semicolon to end a type declaration.
+
+Don't worry if this TypeScript feature seems underwhelming. It's not that useful _on its own_, but rather it becomes very powerful when you pair it with other concepts (like type unions, literal types, intersections, and more).
+
+### p.s. Don't Overuse Aliases
+
+One little tip: be careful not to _over use_ type aliases. A very common mistake beginners make is to create aliases for arrays of things:
+
+```ts
+export interface Row {
+ // imagine some properties here
+}
+
+export type Rows = Row[];
+```
+
+That might seem nice because you can just import `Rows` and use it somewhere in your app where you have an array of Rows.
+
+But, ask yourself:
+
+> can I just import `Row` and specify `Row[]` when needed?
+
+If the answer is yes, then you should probably not make an alias for `Rows`. This is beneficial because you're probably going to want to work with the `Row` type _anyway_ in the same file. It's also a bit easier to read and understand.
+
+## Solving This Challenge
+
+To solve this challenge, make type aliases for `Name`, `Year`, `Payload`, etc. until there are no errors in the tests.
+
+`Name` is started here for you as an example.
diff --git a/challenges/type-aliases/solutions/1.ts b/challenges/type-aliases/solutions/1.ts
new file mode 100644
index 00000000..5b1fe8d5
--- /dev/null
+++ b/challenges/type-aliases/solutions/1.ts
@@ -0,0 +1,11 @@
+type Name = string;
+type Year = number;
+type Count = number;
+type IsOperational = boolean;
+
+type Kilograms = number;
+
+interface Payload {
+ name: Name,
+ mass: Kilograms
+}
\ No newline at end of file
diff --git a/challenges/type-aliases/tests.ts b/challenges/type-aliases/tests.ts
new file mode 100644
index 00000000..f8b59d63
--- /dev/null
+++ b/challenges/type-aliases/tests.ts
@@ -0,0 +1,44 @@
+import { Expect, Equal } from 'type-testing';
+
+type test_Name = Expect<Equal<Name, string>>;
+type test_Year = Expect<Equal<Year, number>>;
+type test_Count = Expect<Equal<Count, number>>;
+type test_IsOperational = Expect<Equal<IsOperational, boolean>>;
+
+type test_PayloadName = Expect<Equal<
+ Payload['name'],
+ string
+>>;
+
+type test_Kilograms = Expect<Equal<
+ Kilograms,
+ number
+>>;
+
+type test_PayloadMass = Expect<Equal<
+ Payload['mass'],
+ Kilograms
+>>;
+
+interface Spacecraft {
+ name: Name;
+ yearBuilt: Year;
+ crewCapacity: Count;
+ launchDate: Date;
+ isOperational: IsOperational;
+ propulsionSystem: string[];
+ payload: Payload[];
+}
+
+const voyager1 = {
+ name: "Voyager 1",
+ yearBuilt: 1977,
+ crewCapacity: 0,
+ launchDate: new Date("1977 09 05"),
+ isOperational: true,
+ propulsionSystem: ["RTG (Radioisotope Thermoelectric Generator)"],
+ payload: [
+ { name: "Golden Record", mass: 0.3 },
+ { name: "Instruments", mass: 721 },
+ ],
+} satisfies Spacecraft;
\ No newline at end of file
diff --git a/challenges/type-aliases/tsconfig.json b/challenges/type-aliases/tsconfig.json
new file mode 100644
index 00000000..875cb600
--- /dev/null
+++ b/challenges/type-aliases/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/challenges/type-aliases/user.ts b/challenges/type-aliases/user.ts
new file mode 100644
index 00000000..7f36eae2
--- /dev/null
+++ b/challenges/type-aliases/user.ts
@@ -0,0 +1,15 @@
+// We completed the first alias (`Name`) for you to see as an example
+type Name = string;
+
+// Now try replacing `unknown` with a primitive data type that might be appropriate for `Year`
+type Year = unknown;
+
+type IsOperational = unknown;
+
+type Payload = {
+ name: Name;
+
+ // the tests show that you need a `mass` property here
+ // but first you might need to create an alias for `Kilograms`
+ // because that's the value of `mass`
+};
diff --git a/challenges/type-unions/metadata.json b/challenges/type-unions/metadata.json
new file mode 100644
index 00000000..678fee58
--- /dev/null
+++ b/challenges/type-unions/metadata.json
@@ -0,0 +1,4 @@
+{
+ "id": "type-unions",
+ "prerequisites": ["type-aliases", "literal-types"]
+}
diff --git a/challenges/type-unions/prompt.md b/challenges/type-unions/prompt.md
new file mode 100644
index 00000000..e03adb39
--- /dev/null
+++ b/challenges/type-unions/prompt.md
@@ -0,0 +1,81 @@
+## What Problem Type Unions Solve
+
+In a previous example for `type-aliases` we saw a problem. We were writing code for a space shuttle and we wanted to make sure that we can't accidentally use the wrong units type.
+
+```ts
+type Meters = number;
+type Miles = number;
+
+const landSpacecraft = (distance: Meters) {
+ // ... do fancy math ...
+}
+```
+
+But we noticed when we call `landSpacecraft` with the wrong literal type (see [the challenge on literal types](todo-link)), there's no error like we might expect:
+
+```ts
+const distanceInMiles: Miles = 1242;
+landSpacecraft(distanceInMiles);
+```
+
+What do we do? We have some places in our code that take a unit of `miles` and some places in our code that take a unit of `meters` and we want to be sure we _NEVER_ mix the two up since it could mean literally destroying the entire spacecraft if we do (even once).
+
+We can use unions!
+
+## How To Use Type Unions
+
+Unions are defined using a single "pipe" character: `|` separating two types or type aliases.
+
+Let's take a look:
+
+```ts
+type Meters = number;
+type Miles = number;
+
+type Distance = Meters | Miles;
+```
+
+That's a good start, but there's still no way for our function to tell the difference between the two, so we _spruce up_ the first two type aliases a bit.
+
+```ts
+type Meters = {
+ unit: 'meters';
+ value: number;
+};
+
+type Miles = {
+ unit: 'miles';
+ value: number;
+};
+
+type Distance = Meters | Miles;
+```
+
+Now check out how we can update `landSpacecraft`:
+
+```ts
+const landSpacecraft = (distance: Distance) => {
+ let meters: Meters = {
+ unit: 'meters',
+ value: distance.unit === 'miles' ? distance.value / 1609.34 : distance.value,
+ };
+ // ... rest of our code
+}
+```
+
+## Properties of Unions
+
+Unions are a very deep topic, actually. The three things you need to know right now are:
+
+1. unions are unordered
+ - and if you implement hacks to try to depend on the order your tests will break across different TypeScript versions
+1. the items in a union are unique
+ - so doing `1 | 1 | 2 | 3` is the same as `1 | 2 | 3`
+1. the `never` type is an empty union
+ - we'll learn more about `never` [later on](todo-never)
+
+## Solving This Challenge
+
+We just started integrating with a new API from a vendor that only publishes data in `feet`. Now we need to update a function `getDistanceInMeters` accordingly.
+
+Then, context switch to a completely different task (realistic, isn't it??) and update the `Position` type's union members until there are no more errors in the test.
diff --git a/challenges/type-unions/solutions/1.ts b/challenges/type-unions/solutions/1.ts
new file mode 100644
index 00000000..1f84e918
--- /dev/null
+++ b/challenges/type-unions/solutions/1.ts
@@ -0,0 +1,31 @@
+// Part 1: Meters
+type Meters = {
+ unit: 'meters';
+ value: number;
+};
+
+type Miles = {
+ unit: 'miles';
+ value: number;
+};
+
+type Feet = {
+ unit: 'feet';
+ value: number;
+}
+
+type Distance = Meters | Miles | Feet;
+
+/////////////////////////////////////////////////
+// Part 2: position
+type Position =
+ | 'topLeft'
+ | 'top'
+ | 'topRight'
+ | 'left'
+ | 'center'
+ | 'right'
+ | 'bottomLeft'
+ | 'bottom'
+ | 'bottomRight'
+;
diff --git a/challenges/type-unions/tests.ts b/challenges/type-unions/tests.ts
new file mode 100644
index 00000000..9aa181de
--- /dev/null
+++ b/challenges/type-unions/tests.ts
@@ -0,0 +1,117 @@
+import { Expect } from 'type-testing';
+import { expect } from 'jest';
+
+const getDistanceInMeters = (distance: Distance) => {
+ switch (distance.unit) {
+ case 'miles':
+ return {
+ unit: 'meters',
+ value: distance.value / 1609.34,
+ } satisfies Meters;
+
+ case 'meters':
+ return {
+ unit: 'meters',
+ value: distance.value,
+ } satisfies Meters;
+
+ case 'feet':
+ return {
+ unit: 'meters',
+ value: distance.value * 3.28084,
+ } satisfies Meters;
+
+ default:
+ // @ts-expect-error (in production codebases, we'd assert an unreachable case here but that's beyond the scope of this lesson)
+ throw new Error(`unrecognized unit: ${distance.unit}`)
+ }
+}
+
+const lowMarsOrbit = {
+ unit: 'meters',
+ value: 300_000
+} satisfies Meters;
+
+const mediumMarsOrbit = {
+ unit: 'meters',
+ value: 2_000_000
+} satisfies Meters;
+
+const highMarsOrbit = {
+ unit: 'meters',
+ value: 5_000_000
+} satisfies Meters;
+
+
+expect(getDistanceInMeters({
+ unit: 'miles',
+ value: 186.41182099494205,
+})).toEqual(lowMarsOrbit);
+
+expect(getDistanceInMeters({
+ unit: 'meters',
+ value: 2_000_000,
+})).toEqual(mediumMarsOrbit);
+
+expect(getDistanceInMeters({
+ unit: 'feet',
+ value: 1523999.9512320017,
+})).toEqual(highMarsOrbit);
+
+
+/////////////////////////////////////////////////
+// Part 2
+
+interface AbsolutePosition {
+ top?: number;
+ right?: number;
+ bottom?: number;
+ left?: number;
+}
+
+const positionElement = (position: Position): AbsolutePosition => {
+ switch (position) {
+ case 'topLeft':
+ return { top: 0, left: 0 };
+
+ case 'top':
+ return { top: 0 };
+
+ case 'topRight':
+ return { top: 0, right: 0 };
+
+ case 'left':
+ return { left: 0 };
+
+ case 'center':
+ return { top: 0, left: 0, bottom: 0, right: 0 };
+
+ case 'right':
+ return { right: 0 };
+
+ case 'bottomLeft':
+ return { bottom: 0, left: 0 };
+
+ case 'bottom':
+ return { bottom: 0 };
+
+ case 'bottomRight':
+ return { bottom: 0, right: 0 };
+
+ default:
+ return {}
+ }
+}
+
+type Extends<T, U> = T extends U ? true : false;
+
+type test_topLeft = Expect<Extends<'topLeft', Position>>;
+type test_top = Expect<Extends<'top', Position>>;
+type test_topRight = Expect<Extends<'topRight', Position>>;
+type test_left = Expect<Extends<'left', Position>>;
+type test_center = Expect<Extends<'center', Position>>;
+type test_right = Expect<Extends<'right', Position>>;
+type test_bottomLeft = Expect<Extends<'bottomLeft', Position>>;
+type test_bottom = Expect<Extends<'bottom', Position>>;
+type test_bottomRight = Expect<Extends<'bottomRight', Position>>;
+
diff --git a/challenges/type-unions/tsconfig.json b/challenges/type-unions/tsconfig.json
new file mode 100644
index 00000000..875cb600
--- /dev/null
+++ b/challenges/type-unions/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/challenges/type-unions/user.ts b/challenges/type-unions/user.ts
new file mode 100644
index 00000000..534d2325
--- /dev/null
+++ b/challenges/type-unions/user.ts
@@ -0,0 +1,16 @@
+// Part 1: Meters
+type Meters = {
+ unit: 'meters';
+ value: number;
+};
+
+type Miles = {
+ unit: 'miles';
+ value: number;
+};
+
+type Distance = Meters | Miles;
+
+/////////////////////////////////////////////////
+// Part 2: position
+type Position = 'top' | 'topLeft' | 'topRight';
diff --git a/challenges/typeof/metadata.json b/challenges/typeof/metadata.json
new file mode 100644
index 00000000..56b6828e
--- /dev/null
+++ b/challenges/typeof/metadata.json
@@ -0,0 +1,4 @@
+{
+ "id": "typeof",
+ "prerequisites": ["literal-types", "type-unions", "type-aliases"]
+}
diff --git a/challenges/typeof/prompt.md b/challenges/typeof/prompt.md
new file mode 100644
index 00000000..e4eb9eff
--- /dev/null
+++ b/challenges/typeof/prompt.md
@@ -0,0 +1,91 @@
+## `typeof`: A Bridge Between Worlds
+
+Have we said thank you, yet, for taking these TypeHero challenges? Well... THANK YOU!
+
+You're doing yourself a great service by improve your knowledge of TypeScript. As you dig deeper, on your quest to become a TypeScript wizard, you're going to start noticing that there are almost two worlds. The "JavaScript" world and the "types" world.
+
+| | JavaScript world | types world |
+| - | - | - |
+| variables | `const`, `let`, function arguments | [type aliases](todo-type-aliases), [default generic arguments](todo-default-generic-arguments) |
+| operations | `for` loops, `while` loops, recursion, higher-order functions | recursion, higher-order types |
+| runtime artifacts | ✅ | ❌ |
+| time of error | runtime | compile time |
+| constructs | statements, expressions | expressions |
+
+Perhaps you see a problem this divide might cause. What happens if you have information in JavaScript that you want to bring over to TypeScript?
+
+<!-- TODO: mermaid diagram https://github.blog/2022-02-14-include-diagrams-markdown-files-mermaid with a remark plugin in `markdown.tsx` -->
+
+```text
+raw data
+| conversion
+| | types
+| | |
+v v v
+JavaScript ==> `typeof` ==> TypeScript
+```
+
+## How to use `typeof`
+
+### `typeof` in JavaScript
+
+You might be familiar with `typeof` as a JavaScript operator. It returns a string indicating the type of a JavaScript value.
+
+```ts
+console.log(typeof "Euler's Number");
+// -> logs the string `'string'`
+
+console.log(typeof 2.7182);
+// -> logs the string `'number'`
+```
+
+But that's JavaScript. The `typeof` actually also exists in TypeScript!
+
+### `typeof` in TypeScript
+
+What if we wanted to use some of our data as a type in TypeScript?
+
+```ts
+const name = "Euler's Number";
+const value = 2.7182;
+
+// we can use `typeof` for type aliases
+type Value = typeof value;
+
+// or we can use it inline for new
+interface FamousNumbers {
+ label: typeof name;
+ value: Value;
+}
+```
+
+```ts
+const count = 42;
+type Count = typeof count;
+```
+
+### `typeof` Is Most Useful For Complex Types
+
+TypeScript keyword that you put before a JavaScript _identifier_ like a variable name. Let's say you have this function in your codebase:
+
+```ts
+const createPoint = (x: number, y: number) => ({ x, y });
+```
+
+You can use `typeof` to _extract_ the type of this JavaScript function and bring it into the realm of TypeScript types:
+
+```ts
+// JavaScript stuff
+// |
+// v----------
+type CreatePoint = typeof createPoint
+//^----------------------
+//|
+//|TypeScript stuff
+```
+
+Later, you're going to learn about ways to then do more operations on types. We're going to be extracting [keys of objects](todo-pick), and creating new types for [return types](todo-return-types) and [parameters](todo-parameters) of functions.
+
+## Solving This Challenge
+
+The tests provide you some data. Try to make all the tests pass by using that data combined with the `typeof` operator.
diff --git a/challenges/typeof/solutions/1.ts b/challenges/typeof/solutions/1.ts
new file mode 100644
index 00000000..21aac102
--- /dev/null
+++ b/challenges/typeof/solutions/1.ts
@@ -0,0 +1,6 @@
+type Width = typeof width;
+type Margin = typeof margin;
+type Data = typeof d3ChartConfig.data;
+type YScale = typeof d3ChartConfig.xScale;
+
+type D3ChartConfig = typeof d3ChartConfig;
diff --git a/challenges/typeof/tests.ts b/challenges/typeof/tests.ts
new file mode 100644
index 00000000..28a0feda
--- /dev/null
+++ b/challenges/typeof/tests.ts
@@ -0,0 +1,101 @@
+import { Expect, Equal } from 'type-testing';
+
+const height = 500;
+const width = 700;
+
+type test_Width = Expect<Equal<
+ Width,
+ number
+>>;
+
+const margin = {
+ top: 20,
+ right: 30,
+ bottom: 40,
+ left: 50,
+};
+
+type test_Margin = Expect<Equal<
+ Margin,
+ { top: 20, right: 30, bottom: 40, left: 50 }
+>>;
+
+const d3ChartConfig = {
+ width,
+ height,
+ margin,
+ data: [
+ { category: 'A', value: 30 },
+ { category: 'B', value: 45 },
+ { category: 'C', value: 60 },
+ { category: 'D', value: 25 },
+ { category: 'E', value: 50 },
+ ],
+ xScale: {
+ type: 'band',
+ domain: data => data.map(d => d.category),
+ range: [0, width - margin.right - margin.left],
+ },
+ yScale: {
+ type: 'linear',
+ domain: [0, (data: number[]) => Math.max(data.length, data[0])],
+ range: [height - margin.bottom, margin.top],
+ },
+ xAxis: {
+ label: 'Categories',
+ tickSize: 5,
+ },
+ yAxis: {
+ label: 'Values',
+ tickSize: 5,
+ },
+ bar: {
+ fill: 'steelblue',
+ },
+};
+
+type test_Data = Expect<Equal<
+ Data,
+ { category: string, value: number }[]
+>>;
+
+type test_YScale = Expect<Equal<
+ YScale,
+ {
+ type: string;
+ domain: (number | ((data: number[]) => number))[],
+ range: number[],
+ }
+>>;
+
+type test_d3ChartConfig = Expect<Equal<
+ D3ChartConfig,
+ {
+ width: number;
+ height: Width;
+ margin: Margin;
+ data: Data;
+ xScale: {
+ type: string;
+ domain: string[];
+ range: [number, number];
+ };
+ yScale: {
+ type: string;
+ domain: [number, number];
+ range: [number, number];
+ };
+ xAxis: {
+ label: string;
+ tickSize: number;
+ };
+ yAxis: {
+ label: string;
+ tickSize: number;
+ };
+ bar: {
+ fill: string;
+ width: number;
+ };
+ }
+>>;
diff --git a/challenges/typeof/tsconfig.json b/challenges/typeof/tsconfig.json
new file mode 100644
index 00000000..875cb600
--- /dev/null
+++ b/challenges/typeof/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "compilerOptions": {}
+}
diff --git a/challenges/typeof/user.ts b/challenges/typeof/user.ts
new file mode 100644
index 00000000..d650f73f
--- /dev/null
+++ b/challenges/typeof/user.ts
@@ -0,0 +1,6 @@
+type Width = typeof width;
+type Margin = unknown;
+type Data = unknown;
+type YScale = unknown;
+
+type D3ChartConfig = unknown;