You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -283,7 +282,7 @@ Finally, we can see that our `test` result has an error because the `result` is
283
282
284
283
Your challenge is to consider how we can change the types to make the errors go away, and to ensure that `result` is a `number`. You can hover over `result` to check it.
285
284
286
-
<Exercisetitle="Exercise 1: Basic Types with Function Parameters"filePath="/src/015-essential-types-and-annotations/020-basic-types-with-function-parameters.problem.ts"></Exercise>
285
+
<Exercisetitle="Exercise 1: Basic Types with Function Parameters"filePath="/src/015-essential-types-and-annotations/020-basic-types-with-function-parameters.problem.ts"resourceId="1fZdJK1AI9JNeRElmqAd9N"></Exercise>
@@ -354,13 +352,13 @@ Type 'boolean' is not assignable to type 'string'.
354
352
355
353
Change the types of the annotations on each variable to make the errors go away.
356
354
357
-
<Exercisetitle="Exercise 3: The Basic Types"filePath="/src/015-essential-types-and-annotations/022-all-types.problem.ts"></Exercise>
355
+
<Exercisetitle="Exercise 3: The Basic Types"filePath="/src/015-essential-types-and-annotations/022-all-types.problem.ts"resourceId="NMpTvrI4rUCyVa4GVzY1iN"></Exercise>
358
356
359
357
#### Exercise 4: The `any` Type
360
358
361
359
Here is a function called `handleFormData` that accepts an `e` typed as `any`. The function prevents the default form submission behavior, then creates an object from the form data and returns it:
362
360
363
-
```ts twoslash
361
+
```ts
364
362
const handleFormData = (e:any) => {
365
363
e.preventDefault();
366
364
@@ -414,7 +412,7 @@ Why is this error happening? Why isn't TypeScript giving us an error here?
414
412
415
413
I'll give you a clue. I've hidden a nasty typo in there. Can you fix it?
416
414
417
-
<Exercisetitle="Exercise 4: The `any` Type"filePath="/src/015-essential-types-and-annotations/032.5-any.problem.ts"></Exercise>
415
+
<Exercisetitle="Exercise 4: The `any` Type"filePath="/src/015-essential-types-and-annotations/032.5-any.problem.ts"resourceId="1fZdJK1AI9JNeRElmqAeU3"></Exercise>
418
416
419
417
#### Solution 1: Basic Types with Function Parameters
420
418
@@ -518,7 +516,7 @@ Using `any` also disables useful features like autocompletion, which can help yo
518
516
519
517
That's right-- the error in the above code was caused by a typo of `e.terget` instead of `e.target` when creating the `FormData`!
520
518
521
-
```ts twoslash
519
+
```ts
522
520
const handleFormData = (e:any) => {
523
521
e.preventDefault();
524
522
@@ -604,7 +602,7 @@ We can tell from the `concatName` function body that it expects `user.first` and
604
602
605
603
How could we type the `user` parameter to ensure that it has these properties and that they are of the correct type?
@@ -839,7 +837,7 @@ Even though everything is working as expected, there's an opportunity for refact
839
837
840
838
How could you use the `type` keyword to make this code more readable?
841
839
842
-
<Exercisetitle="Exercise 1: The `type` Keyword"filePath="/src/015-essential-types-and-annotations/027-type-keyword.problem.ts"></Exercise>
840
+
<Exercisetitle="Exercise 1: The `type` Keyword"filePath="/src/015-essential-types-and-annotations/027-type-keyword.problem.ts"resourceId="jUJqrXCHRph0Z4Fs6Ll3za"></Exercise>
843
841
844
842
#### Solution 1: The `type` Keyword
845
843
@@ -1051,7 +1049,7 @@ As the error message points out, there is not currently a property called `items
@@ -1088,7 +1086,7 @@ Object literal may only specify known properties, and 'ingredients' does not exi
1088
1086
1089
1087
By combining what you've seen with typing object properties and working with arrays, how would you specify ingredients for the `Recipe` type?
1090
1088
1091
-
<Exercisetitle="Exercise 2: Arrays of Objects"filePath="/src/015-essential-types-and-annotations/029-arrays-of-objects.problem.ts"></Exercise>
1089
+
<Exercisetitle="Exercise 2: Arrays of Objects"filePath="/src/015-essential-types-and-annotations/029-arrays-of-objects.problem.ts"resourceId="YgFRxBViy44CfW0H2dToDx"></Exercise>
1092
1090
1093
1091
#### Exercise 3: Tuples
1094
1092
@@ -1143,7 +1141,7 @@ setRange([0, 10, 20]);
1143
1141
1144
1142
The code for the `setRange` function needs an updated type annotation to specify that it only accepts a tuple of two numbers.
// Do something with latitude, longitude, and elevation in here
1163
1161
1164
1162
typetests= [
1165
-
Expect<Equal<typeoflatitude, number>>,// red squiggly line under Equal<> statement
1166
-
Expect<Equal<typeoflongitude, number>>,// red squiggly line under Equal<> statement
1163
+
Expect<Equal<typeoflatitude, number>>,
1164
+
Expect<Equal<typeoflongitude, number>>,
1167
1165
Expect<Equal<typeofelevation, number|undefined>>,
1168
1166
];
1169
1167
};
1170
1168
```
1171
1169
1172
1170
Your challenge is to update the type annotation for the `coordinates` parameter to specify that it should be a tuple of three numbers, where the third number is optional.
1173
1171
1174
-
<Exercisetitle="Exercise 4: Optional Members of Tuples"filePath="/src/015-essential-types-and-annotations/032-optional-members-of-tuples.problem.ts"></Exercise>
1172
+
<Exercisetitle="Exercise 4: Optional Members of Tuples"filePath="/src/015-essential-types-and-annotations/032-optional-members-of-tuples.problem.ts"resourceId="jUJqrXCHRph0Z4Fs6Ll7aP"></Exercise>
Try to use an optional parameter annotation to fix the error.
1874
1870
1875
-
<Exercisetitle="Exercise 1: Optional Function Parameters"filePath="/src/015-essential-types-and-annotations/023-optional-function-parameters.problem.ts"></Exercise>
1871
+
<Exercisetitle="Exercise 1: Optional Function Parameters"filePath="/src/015-essential-types-and-annotations/023-optional-function-parameters.problem.ts"resourceId="1fZdJK1AI9JNeRElmqAdVv"></Exercise>
Update the `concatName` function to use `Pocock` as the default last name if one is not provided.
1932
1928
1933
-
<Exercisetitle="Exercise 2: Default Function Parameters"filePath="/src/015-essential-types-and-annotations/024-default-function-parameters.problem.ts"></Exercise>
1929
+
<Exercisetitle="Exercise 2: Default Function Parameters"filePath="/src/015-essential-types-and-annotations/024-default-function-parameters.problem.ts"resourceId="1fZdJK1AI9JNeRElmqAdoi"></Exercise>
1934
1930
1935
1931
#### Exercise 3: Rest Parameters
1936
1932
@@ -1959,7 +1955,7 @@ The test passes, but there's an error on the `...strings` rest parameter.
1959
1955
1960
1956
How would you update the rest parameter to specify that it should be an array of strings?
How would you type `makeChange` as a function takes in a `User` and returns a `User`?
2035
2030
2036
-
<Exercisetitle="Exercise 4: Function Types"filePath="/src/015-essential-types-and-annotations/033-function-types.problem.ts"></Exercise>
2031
+
<Exercisetitle="Exercise 4: Function Types"filePath="/src/015-essential-types-and-annotations/033-function-types.problem.ts"resourceId="1fZdJK1AI9JNeRElmqAeqb"></Exercise>
0 commit comments