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
When you hit `Ctrl + Space` inside the object, you'll see a list of the possible properties based on the `MyObj` type:
@@ -282,6 +282,8 @@ let element = document.getElementById(12);
282
282
283
283
How can hovering help to determine what argument `document.getElementById` actually requires? And for a bonus point, what type is `element`?
284
284
285
+
<Exercisetitle="Exercise 1: Hovering a Function Call"filePath="/src/016.5-ide-superpowers/041-hovering-a-function-call.problem.ts" />
286
+
285
287
#### Solution 1: Hovering a Function Call
286
288
287
289
First of all, we can hover over the red squiggly error itself. In this case, hovering over `12`, we get the following error message:
@@ -361,6 +363,8 @@ In order to understand what this function does, you'd have to read the code.
361
363
362
364
Add some documentation to the function so that when you hover over it, you can read a description of what it does.
363
365
366
+
<Exercisetitle="Exercise 1: Adding Documentation For Hovers"filePath="/src/016.5-ide-superpowers/042-adding-tsdoc-comments-for-hovers.problem.ts" />
367
+
364
368
#### Solution 1: Adding Documentation for Hovers
365
369
366
370
In this case, we'll specify that the function "Adds two numbers together". We can also use an `@example` tag to show an example of how the function is used:
@@ -508,6 +512,8 @@ Highlight a variable, line, or entire code block then hit `Command + .` to open
508
512
509
513
Experiment with different options to see how they affect the example function.
Copy file name to clipboardExpand all lines: book-content/chapters/04-essential-types-and-annotations.md
+100Lines changed: 100 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -285,6 +285,11 @@ Finally, we can see that our `test` result has an error because the `result` is
285
285
286
286
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.
287
287
288
+
<Exercise
289
+
title="Exercise 1: Basic Types with Function Parameters"
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:
@@ -410,6 +425,11 @@ Why is this error happening? Why isn't TypeScript giving us an error here?
410
425
411
426
I'll give you a clue. I've hidden a nasty typo in there. Can you fix it?
This `goToLocation` function takes in an array of coordinates. Each coordinate has a `latitude` and `longitude`, which are both numbers, as well as an optional `elevation` which is also a number:
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.
Here, we have a `modifyUser` function that takes in an array of `users`, an `id` of the user that we want to change, and a `makeChange` function that makes that change:
@@ -2003,6 +2083,11 @@ modifyUser(
2003
2083
2004
2084
How would you type `makeChange` as a function takes in a `User` and returns a `User`?
0 commit comments