Skip to content

Commit 852c69c

Browse files
committed
Twoslashed 03 and 04
1 parent f5a1fdf commit 852c69c

File tree

4 files changed

+230
-200
lines changed

4 files changed

+230
-200
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"github.copilot.enable": {
55
"*": false,
66
"plaintext": false,
7-
"markdown": false,
7+
"markdown": true,
88
"scminput": false
99
},
1010
"markdownlint.config": {

book-content/chapters/03-typescript-in-the-development-pipeline.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ As an example, we'll be looking at using TypeScript to build a web application.
88

99
Consider this TypeScript file `example.ts` that contains a `run` function that logs a message to the console:
1010

11-
```typescript
11+
```ts twoslash
1212
const run = (message: string) => {
1313
console.log(message);
1414
};
@@ -48,7 +48,7 @@ The problem is that browsers (and other runtimes like Node.js) can't understand
4848

4949
In the case of the `run` function, the `: string` after `message` in the function declaration is not valid JavaScript:
5050

51-
```typescript
51+
```ts twoslash
5252
const run = (message: string) => {
5353
// `: string` is not valid JavaScript!
5454

@@ -58,8 +58,9 @@ const run = (message: string) => {
5858

5959
Removing `: string` gives us something that looks a bit more like JavaScript, but now TypeScript displays an error underneath `message`:
6060

61-
```typescript
62-
const run = (message) => {}; // red squiggly line under message
61+
```ts twoslash
62+
// @errors: 7006
63+
const run = (message) => {};
6364
```
6465

6566
Hovering over the red squiggly line in VS Code, we can see that TypeScript's error message is telling us that `message` implicitly has an `any` type.
@@ -194,12 +195,13 @@ If `tsc` encounters an error, it will display the error in the terminal and the
194195

195196
For example, try changing the `message: string` to `message: number` in the `run` function inside of `example.ts`:
196197

197-
```typescript
198+
```ts twoslash
199+
// @errors: 2345
198200
const run = (message: number) => {
199201
console.log(message);
200202
};
201203

202-
run("Hello world!"); // red squiggly line under "Hello world!"
204+
run("Hello world!");
203205
```
204206

205207
Inside the terminal, `tsc` will display an error message:

0 commit comments

Comments
 (0)