Skip to content

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

adds metadata validation + `label`/`description` for all challenges (#888)

Dimitri Mitropoulosb942fe17a51f
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 14d1bbdd..968b8419 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -10,6 +10,10 @@
{
"fileMatch": ["vercel.json"],
"url": "https://openapi.vercel.sh/vercel.json"
+ },
+ {
+ "fileMatch": ["challenges/**/metadata.json"],
+ "url": "./challenges/metadata.schema.json"
}
],
"search.exclude": {
diff --git a/challenges/blank/metadata.json b/challenges/blank/metadata.json
index 6d38c914..0a467610 100644
--- a/challenges/blank/metadata.json
+++ b/challenges/blank/metadata.json
@@ -1,4 +1,7 @@
{
"id": "lower-snake-case",
+ "label": "Lower Snake Case",
+ "description": "Try to keep it to one shortish sentence.",
+ "difficulty": "beginner",
"prerequisites": []
}
diff --git a/challenges/generic-type-arguments/metadata.json b/challenges/generic-type-arguments/metadata.json
index 55bc81aa..5b9760e4 100644
--- a/challenges/generic-type-arguments/metadata.json
+++ b/challenges/generic-type-arguments/metadata.json
@@ -1,5 +1,7 @@
{
"id": "generic-type-arguments",
+ "label": "Generic Type Arguments",
+ "description": "Generic types are like functions, and functions need inputs. That's what generic type arguments are.",
"difficulty": "beginner",
"prerequisites": ["primitive-data-types", "type-aliases"]
}
diff --git a/challenges/generic-type-constraints/metadata.json b/challenges/generic-type-constraints/metadata.json
index b71b4219..e962dad8 100644
--- a/challenges/generic-type-constraints/metadata.json
+++ b/challenges/generic-type-constraints/metadata.json
@@ -1,5 +1,7 @@
{
"id": "generic-type-constraints",
+ "label": "Generic Type Constraints",
+ "description": "Generic type constraints allow us to restrict the possible types a generic type will accept.",
"difficulty": "beginner",
"prerequisites": []
}
diff --git a/challenges/index-signatures/metadata.json b/challenges/index-signatures/metadata.json
index 7cc045a6..047b9dfe 100644
--- a/challenges/index-signatures/metadata.json
+++ b/challenges/index-signatures/metadata.json
@@ -1,5 +1,7 @@
{
"id": "index-signatures",
+ "label": "Index Signatures",
+ "description": "Index signatures allow us to handle types where the properties are a non-specific literal value.",
"difficulty": "beginner",
"prerequisites": ["type-aliases", "primitive-data-types"]
}
diff --git a/challenges/index-signatures/prompt.md b/challenges/index-signatures/prompt.md
index e0e239fe..173f51bc 100644
--- a/challenges/index-signatures/prompt.md
+++ b/challenges/index-signatures/prompt.md
@@ -4,7 +4,7 @@ It's common in any language to make general purpose mappings of one type to anot
Look at this theoretical API response from your company. This is a `/followerCountByUser` endpoint and we pass in some user we're looking
-```
+```text
https://yourcompany.com/api/v1/followerCountByUser
```
@@ -105,4 +105,4 @@ type FollowerCountByUser = {
## Solving This Challenge
-Take a look at the tests. You'll see some
\ No newline at end of file
+Take a look at the tests. You'll see some objects. Try to make types (using index signatures) that match those objects.
diff --git a/challenges/index-signatures/tests.ts b/challenges/index-signatures/tests.ts
index b01111c1..cd7372a8 100644
--- a/challenges/index-signatures/tests.ts
+++ b/challenges/index-signatures/tests.ts
@@ -17,7 +17,6 @@ const groceryList: GroceryList = {
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'],
diff --git a/challenges/indexed-types/metadata.json b/challenges/indexed-types/metadata.json
index 791dba0d..27d788d6 100644
--- a/challenges/indexed-types/metadata.json
+++ b/challenges/indexed-types/metadata.json
@@ -1,5 +1,7 @@
{
"id": "indexed-types",
+ "label": "Indexed Types",
+ "description": "Some types can be indexed (sorta like you would index an array or an object) to lookup a particular value.",
"difficulty": "beginner",
"prerequisites": ["primitive-types", "type-unions", "keyof", "literal-types"]
}
diff --git a/challenges/keyof/metadata.json b/challenges/keyof/metadata.json
index 25a629f9..bcf1dd61 100644
--- a/challenges/keyof/metadata.json
+++ b/challenges/keyof/metadata.json
@@ -1,5 +1,7 @@
{
"id": "keyof",
+ "label": "The `keyof` operator",
+ "description": "`keyof` allows us to extract a union of another type's keys.",
"difficulty": "beginner",
"prerequisites": ["type-aliases", "literal-types", "type-unions"]
}
diff --git a/challenges/literal-types/metadata.json b/challenges/literal-types/metadata.json
index 34f6d2d7..17d25e7a 100644
--- a/challenges/literal-types/metadata.json
+++ b/challenges/literal-types/metadata.json
@@ -1,5 +1,7 @@
{
"id": "literal-types",
+ "label": "Literal Types",
+ "description": "TypeScript can be more specific than `string` or `number`. It can remember literal values.",
"difficulty": "beginner",
"prerequisites": ["primitive-data-types", "type-unions"]
}
diff --git a/challenges/literal-types/prompt.md b/challenges/literal-types/prompt.md
index fbc72bad..df48d4de 100644
--- a/challenges/literal-types/prompt.md
+++ b/challenges/literal-types/prompt.md
@@ -2,7 +2,7 @@
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 :)
+> side note: 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.
@@ -66,7 +66,7 @@ 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?
+The TLDR; is: once you pair type unions with literals, you can start _discriminating_ 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
diff --git a/challenges/mapped-object-types/metadata.json b/challenges/mapped-object-types/metadata.json
index a21af54d..99022101 100644
--- a/challenges/mapped-object-types/metadata.json
+++ b/challenges/mapped-object-types/metadata.json
@@ -1,5 +1,7 @@
{
"id": "mapped-object-types",
+ "label": "Mapped Object Types",
+ "description": "Mapping objects is a foundational skill that allows you to write type translation logic.",
"difficulty": "beginner",
"prerequisites": ["index-signatures", "keyof", "generic-type-arguments", "indexed-types"]
}
diff --git a/challenges/metadata.schema.json b/challenges/metadata.schema.json
new file mode 100644
index 00000000..f435a420
--- /dev/null
+++ b/challenges/metadata.schema.json
@@ -0,0 +1,34 @@
+{
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "type": "object",
+ "properties": {
+ "id": {
+ "description": "a snake-case-style slug that will also be used in URLs (and, therefore, needs SEO considerations)",
+ "maxLength": 25,
+ "type": "string"
+ },
+ "label": {
+ "description": "A few capitalized words (often just a capitalized version of the slug) that the user will see for the challenge.",
+ "maxLength": 25,
+ "type": "string"
+ },
+ "description": {
+ "description": "Try to keep it to one shortish sentence.",
+ "maxLength": 100,
+ "type": "string"
+ },
+ "difficulty": {
+ "description": "The difficulty level for this challenge.",
+ "type": "string",
+ "enum": ["beginner", "easy", "medium", "hard", "extreme"]
+ },
+ "prerequisites": {
+ "description": "An array of ids of other challenges that this challenge is written as to expect the reader to already understand.",
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ }
+ },
+ "required": ["id", "label", "description", "difficulty", "prerequisites"]
+}
diff --git a/challenges/pick/metadata.json b/challenges/pick/metadata.json
index 14ad63cd..2aac4d1f 100644
--- a/challenges/pick/metadata.json
+++ b/challenges/pick/metadata.json
@@ -1,5 +1,7 @@
{
"id": "pick",
+ "label": "The `Pick` builtin",
+ "description": "TypeScript ships with a `Pick` type. Learn how to make it yourself!",
"difficulty": "easy",
"prerequisites": ["literal-types", "keyof", "mapped-object-types", "generic-type-constraints"]
}
diff --git a/challenges/pick/prompt.md b/challenges/pick/prompt.md
index a177b506..40dd0457 100644
--- a/challenges/pick/prompt.md
+++ b/challenges/pick/prompt.md
@@ -142,8 +142,8 @@ console.log(pickYourPokemon(pikachu))
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
-
+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'`.
+
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/primitive-data-types/metadata.json b/challenges/primitive-data-types/metadata.json
index fa5d4dc9..a955d8c2 100644
--- a/challenges/primitive-data-types/metadata.json
+++ b/challenges/primitive-data-types/metadata.json
@@ -1,5 +1,7 @@
{
"id": "primitive-data-types",
+ "label": "Primitive Data Types",
+ "description": "Your TypeScript journey starts with these building blocks.",
"difficulty": "beginner",
"prerequisites": []
}
diff --git a/challenges/type-aliases/metadata.json b/challenges/type-aliases/metadata.json
index 38584778..bb348c47 100644
--- a/challenges/type-aliases/metadata.json
+++ b/challenges/type-aliases/metadata.json
@@ -1,5 +1,7 @@
{
"id": "type-aliases",
+ "label": "Type Aliases",
+ "description": "You can create multiple names for the same type.",
"difficulty": "beginner",
"prerequisites": ["primitive-data-types"]
}
diff --git a/challenges/type-unions/metadata.json b/challenges/type-unions/metadata.json
index c9e3c682..4868f31f 100644
--- a/challenges/type-unions/metadata.json
+++ b/challenges/type-unions/metadata.json
@@ -1,5 +1,7 @@
{
"id": "type-unions",
+ "label": "Type Unions",
+ "description": "Type unions are a powerful tool that allow you to create a type that's many values all at once.",
"difficulty": "beginner",
"prerequisites": ["type-aliases", "literal-types"]
}
diff --git a/challenges/type-unions/prompt.md b/challenges/type-unions/prompt.md
index e03adb39..1102a195 100644
--- a/challenges/type-unions/prompt.md
+++ b/challenges/type-unions/prompt.md
@@ -68,11 +68,11 @@ const landSpacecraft = (distance: Distance) => {
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
+ a. 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`
+ a. 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)
+ a. we'll learn more about `never` [later on](todo-never)
## Solving This Challenge
diff --git a/challenges/typeof/metadata.json b/challenges/typeof/metadata.json
index aaf816df..a23e81e6 100644
--- a/challenges/typeof/metadata.json
+++ b/challenges/typeof/metadata.json
@@ -1,5 +1,7 @@
{
"id": "typeof",
+ "label": "The `typeof` Operator",
+ "description": "When you need to create a type from existing JavaScript values, `typeof` is the tool for the job.",
"difficulty": "beginner",
"prerequisites": ["literal-types", "type-unions", "type-aliases"]
}