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
Copy file name to clipboardExpand all lines: apps/site/pages/en/learn/typescript/transpile.md
+1-27Lines changed: 1 addition & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,6 +71,7 @@ If you have type errors in your TypeScript code, the TypeScript compiler will ca
71
71
We will modify our code like this, to voluntarily introduce a type error:
72
72
73
73
```ts
74
+
// @errors: 2322 2554
74
75
typeUser= {
75
76
name:string;
76
77
age:number;
@@ -88,31 +89,4 @@ const justine: User = {
88
89
const isJustineAnAdult:string=isAdult(justine, "I shouldn't be here!");
89
90
```
90
91
91
-
And this is what TypeScript has to say about this:
92
-
93
-
```console
94
-
example.ts:12:5 - error TS2322: Type 'string' is not assignable to type 'number'.
95
-
96
-
12 age: 'Secret!',
97
-
~~~
98
-
99
-
example.ts:3:5
100
-
3 age: number;
101
-
~~~
102
-
The expected type comes from property 'age' which is declared here on type 'User'
103
-
104
-
example.ts:15:7 - error TS2322: Type 'boolean' is not assignable to type 'string'.
105
-
106
-
15 const isJustineAnAdult: string = isAdult(justine, "I shouldn't be here!");
107
-
~~~~~~~~~~~~~~~~
108
-
109
-
example.ts:15:51 - error TS2554: Expected 1 arguments, but got 2.
110
-
111
-
15 const isJustineAnAdult: string = isAdult(justine, "I shouldn't be here!");
112
-
~~~~~~~~~~~~~~~~~~~~~~
113
-
114
-
115
-
Found 3 errors in the same file, starting at: example.ts:12
116
-
```
117
-
118
92
As you can see, TypeScript is very helpful in catching bugs before they even happen. This is one of the reasons why TypeScript is so popular among developers.
0 commit comments