@@ -8,7 +8,7 @@ As an example, we'll be looking at using TypeScript to build a web application.
8
8
9
9
Consider this TypeScript file ` example.ts ` that contains a ` run ` function that logs a message to the console:
10
10
11
- ``` typescript
11
+ ``` ts twoslash
12
12
const run = (message : string ) => {
13
13
console .log (message );
14
14
};
@@ -48,7 +48,7 @@ The problem is that browsers (and other runtimes like Node.js) can't understand
48
48
49
49
In the case of the ` run ` function, the ` : string ` after ` message ` in the function declaration is not valid JavaScript:
50
50
51
- ``` typescript
51
+ ``` ts twoslash
52
52
const run = (message : string ) => {
53
53
// `: string` is not valid JavaScript!
54
54
@@ -58,8 +58,9 @@ const run = (message: string) => {
58
58
59
59
Removing ` : string ` gives us something that looks a bit more like JavaScript, but now TypeScript displays an error underneath ` message ` :
60
60
61
- ``` typescript
62
- const run = (message ) => {}; // red squiggly line under message
61
+ ``` ts twoslash
62
+ // @errors: 7006
63
+ const run = (message ) => {};
63
64
```
64
65
65
66
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
194
195
195
196
For example, try changing the ` message: string ` to ` message: number ` in the ` run ` function inside of ` example.ts ` :
196
197
197
- ``` typescript
198
+ ``` ts twoslash
199
+ // @errors: 2345
198
200
const run = (message : number ) => {
199
201
console .log (message );
200
202
};
201
203
202
- run (" Hello world!" ); // red squiggly line under "Hello world!"
204
+ run (" Hello world!" );
203
205
```
204
206
205
207
Inside the terminal, ` tsc ` will display an error message:
0 commit comments