1
00:00:01,130 --> 00:00:05,060
Now that we've gotten through some administrative stuff, we're now going to dive into our first technical

2
00:00:05,060 --> 00:00:07,670
topic and start to discuss exactly what typescript is.

3
00:00:07,850 --> 00:00:10,580
So what is TypeScript, you know, what are we doing here?

4
00:00:11,360 --> 00:00:16,070
Well, at the end of the day, I want you to imagine that when we write typescript code, we are really

5
00:00:16,070 --> 00:00:17,750
just writing JavaScript.

6
00:00:17,900 --> 00:00:19,090
That's what's really happening here.

7
00:00:19,100 --> 00:00:20,990
We're still writing JavaScript.

8
00:00:21,410 --> 00:00:27,530
All the knowledge you have around JavaScript like arrays, objects, functions and even E 2015 syntax

9
00:00:27,530 --> 00:00:30,710
like restructuring and error functions and classes.

10
00:00:31,070 --> 00:00:34,220
All that knowledge still applies to the world of TypeScript as well.

11
00:00:34,930 --> 00:00:39,590
The only thing that we're really doing with TypeScript is adding in a little bit additional syntax to

12
00:00:39,590 --> 00:00:42,890
our code to handle something called the type system.

13
00:00:43,580 --> 00:00:48,020
This is what TypeScript is all about, as you might guess, and it's what we're going to spend the vast

14
00:00:48,020 --> 00:00:49,730
majority of this course learning about.

15
00:00:50,880 --> 00:00:54,450
So let's get a quick overview on the type system and understand what's going on with it.

16
00:00:55,640 --> 00:00:59,240
The goal of the type system is to help us catch errors during development.

17
00:00:59,270 --> 00:01:04,400
In other words, when we're actually writing our code in our code editor, think about how we catch

18
00:01:04,400 --> 00:01:06,410
errors right now with JavaScript code.

19
00:01:07,100 --> 00:01:10,970
Let's imagine that you're writing out some amount of JavaScript inside of your editor and maybe there's

20
00:01:10,970 --> 00:01:12,130
a bug inside of it.

21
00:01:12,650 --> 00:01:13,820
How would you find that bug?

22
00:01:14,740 --> 00:01:19,210
Well, really, with JavaScript, the only way to do that is to actually execute your code and see that

23
00:01:19,210 --> 00:01:22,090
air up here, and that's not super efficient.

24
00:01:23,110 --> 00:01:28,600
So as an improvement to the development workflow, we use the type system to help us catch errors during

25
00:01:28,600 --> 00:01:34,390
development while you and I are writing our code, typescript is going to be constantly analyzing it

26
00:01:34,540 --> 00:01:35,740
and looking for bugs.

27
00:01:36,340 --> 00:01:41,590
If it finds any possible bug, it's then going to pop open an error message inside of your code editor

28
00:01:41,710 --> 00:01:43,840
and tell you, hey, something might be wrong here.

29
00:01:44,870 --> 00:01:49,100
And that's going to essentially be a signal to you as a developer that you might need to fix up your

30
00:01:49,100 --> 00:01:49,460
code.

31
00:01:51,470 --> 00:01:56,720
Not to do this, er checking the typescript compiler is going to use something called type annotations

32
00:01:56,720 --> 00:02:02,120
to analyze our code base, you and I are going to be responsible for adding in these type annotations.

33
00:02:02,570 --> 00:02:07,580
You can kind of think of these type annotations as being like little comments to describe the purpose

34
00:02:07,580 --> 00:02:11,330
of our code or the information that is flowing through our program.

35
00:02:12,740 --> 00:02:18,650
The type system is only active during development, so in other words, once we go to deploy our application

36
00:02:18,680 --> 00:02:23,950
or even run it inside of our browser in a development environment, the entire type system falls away.

37
00:02:24,710 --> 00:02:27,440
Your browser has no idea what typescript is.

38
00:02:27,620 --> 00:02:31,650
And Narges likewise, no, JSC has no idea what typescript is either.

39
00:02:32,270 --> 00:02:35,060
So all this extra syntax are going to add into our code.

40
00:02:35,240 --> 00:02:36,980
Never makes it into the browser.

41
00:02:36,980 --> 00:02:38,820
It never makes it into Noguez.

42
00:02:38,900 --> 00:02:43,370
We're going to first compile our typescript and we're going to get some JavaScript out of that.

43
00:02:44,150 --> 00:02:46,670
And that JavaScript is what we're going to actually execute.

44
00:02:47,880 --> 00:02:51,660
Finally, this is something I want to point out, just because it's a little bit different than other

45
00:02:51,660 --> 00:02:57,630
languages that are strongly typed, the typescript compiler does not do any performance optimization

46
00:02:57,630 --> 00:02:58,230
whatsoever.

47
00:02:58,950 --> 00:03:01,140
Now, this is very different than many other languages.

48
00:03:01,140 --> 00:03:06,810
In many other languages, the type system can be used to optimize some code that you write using the

49
00:03:06,810 --> 00:03:07,380
compiler.

50
00:03:07,740 --> 00:03:09,570
But that is not the case here with TypeScript.

51
00:03:10,970 --> 00:03:15,380
All right, so that kind of help you understand this process here, let's run through the common scenario

52
00:03:15,380 --> 00:03:20,020
of how we're going to actually write some code and run it inside the browser or with Narges.

53
00:03:20,970 --> 00:03:25,590
So you and I are going to write some type code inside of our editor and remember, we can think of TypeScript

54
00:03:25,590 --> 00:03:30,150
as really just being plain JavaScript, but with these type annotation things added in.

55
00:03:31,460 --> 00:03:36,410
Then once we want to actually run our code, we're going to feed that code into the typescript compiler.

56
00:03:36,920 --> 00:03:42,800
This is a command line tool that's going to read our code, check it for any possible errors, and then

57
00:03:42,800 --> 00:03:45,230
convert it into plain JavaScript.

58
00:03:47,150 --> 00:03:52,430
You and I are then going to take that JavaScript code and feed it into the browser or into Noguez and

59
00:03:52,430 --> 00:03:53,630
finally execute it.

60
00:03:54,980 --> 00:04:00,620
So, again, we do not execute, typescript, we always are executing JavaScript, and so when I say

61
00:04:00,620 --> 00:04:05,420
that you and I are still writing technically JavaScript code here, it is, because the code we're writing,

62
00:04:05,420 --> 00:04:07,550
it is going to end up as JavaScript.

63
00:04:07,550 --> 00:04:11,000
Just it has these extra little type annotation things in it.

64
00:04:12,380 --> 00:04:16,579
All right, so to give you a really practical example of this, I want to show you a quick little Web

65
00:04:16,579 --> 00:04:17,130
page here.

66
00:04:17,450 --> 00:04:20,060
This is a in browser type script compiler.

67
00:04:20,100 --> 00:04:22,640
It's going to open up this link inside of a new browser tab.

68
00:04:23,890 --> 00:04:27,310
Now, on the left hand side, you're going to see a little bit of typescript code, and I know this

69
00:04:27,310 --> 00:04:31,720
is kind of cut off right there, but I just want to give you the impression that this tight script right

70
00:04:31,720 --> 00:04:34,120
here has a bunch of additional syntax in it.

71
00:04:34,270 --> 00:04:34,560
Right.

72
00:04:34,720 --> 00:04:35,720
Just take a look at this code.

73
00:04:35,740 --> 00:04:37,370
We don't need to understand what it does.

74
00:04:37,630 --> 00:04:43,090
You can tell at just a glance that there's a lot of extra stuff in here and it does not look like normal

75
00:04:43,090 --> 00:04:43,720
JavaScript.

76
00:04:45,350 --> 00:04:50,180
So on the left hand side, we've got the typescript, this page is going to compile that code and then

77
00:04:50,180 --> 00:04:53,240
print out the equivalent JavaScript on the right hand side.

78
00:04:53,840 --> 00:04:56,030
So this is the output from the typescript compiler.

79
00:04:56,240 --> 00:05:00,050
And looking at that, yep, it sure looks like plain JavaScript.

80
00:05:01,670 --> 00:05:05,270
So I can't say it enough, like I said, I'm going to repeat it many times throughout this course,

81
00:05:05,390 --> 00:05:07,460
we're still writing JavaScript code.

82
00:05:07,640 --> 00:05:11,660
We're just adding in little extra pieces of syntax here and there.

83
00:05:12,440 --> 00:05:17,510
And these extra pieces of syntax are meant to help the typescript compiler understand what we're trying

84
00:05:17,510 --> 00:05:20,570
to do with our code base so it can help us catch errors.

85
00:05:20,960 --> 00:05:21,530
That's it.

86
00:05:21,530 --> 00:05:23,030
That's the entire typescript world.

87
00:05:24,310 --> 00:05:26,950
All right, let's do a quick wrap up on what we learned in this video.

88
00:05:27,220 --> 00:05:30,300
So first off, when we write TypeScript, we're still writing JavaScript.

89
00:05:30,300 --> 00:05:33,130
We're just adding in these extra little type annotation things.

90
00:05:34,220 --> 00:05:39,110
Secondly, typescript has no effect on how our code actually gets executed, in other words, there

91
00:05:39,110 --> 00:05:42,020
is no performance optimization or anything like that.

92
00:05:43,300 --> 00:05:48,040
Now, finally, the best way to think of TypeScript, in my opinion or kind of an effective analogy,

93
00:05:48,040 --> 00:05:52,600
is to think of TypeScript as being like a friend who is sitting behind you while you are writing code.

94
00:05:53,050 --> 00:05:57,880
And maybe that friend is looking at every line of code you're writing and helping you catch errors.

95
00:05:58,220 --> 00:06:00,090
That's what TypeScript is really doing for us.

96
00:06:00,370 --> 00:06:02,710
It is a helper to help us catch errors.

97
00:06:03,250 --> 00:06:07,880
It doesn't actually have any impact on the final code that we output or the actual code that we run

98
00:06:07,880 --> 00:06:08,700
inside the browser.

99
00:06:08,890 --> 00:06:11,110
It's just there during development.

100
00:06:12,420 --> 00:06:14,410
OK, so now we've got a better idea of TypeScript.

101
00:06:14,430 --> 00:06:18,150
Let's take a quick pause right here and we're going to do a little bit of environment set up in the

102
00:06:18,150 --> 00:06:18,780
next video.

