0
1
00:00:00,221 --> 00:00:05,401
Alright, so in this video we're
going to talk about types. So
1

2
00:00:05,401 --> 00:00:08,881
with typescript you have
several types. But we're going
2

3
00:00:08,881 --> 00:00:13,041
to first work with primitives.
So primitives are the most
3

4
00:00:13,041 --> 00:00:17,401
basic types, okay? We have
number, string and boolean in
4

5
00:00:17,401 --> 00:00:20,321
lowercase, that's very
important. And then
5

6
00:00:20,321 --> 00:00:24,401
where we're going to discover
other types, okay? So these are
6

7
00:00:24,401 --> 00:00:28,241
I would say the the everyday
types that we're going to use,
7

8
00:00:28,241 --> 00:00:31,361
okay? So all of these ones, so
the primitives and this part of
8

9
00:00:31,361 --> 00:00:35,121
the advanced types. So arrays,
objects, functions,
9

10
00:00:35,121 --> 00:00:38,481
enameration, null and undefined
and void. Obviously we're going
10

11
00:00:38,481 --> 00:00:43,281
to cover all these types. And
then we have more occasional
11

12
00:00:43,281 --> 00:00:49,121
types so unknown never any so
any is very special because
12

13
00:00:49,121 --> 00:00:52,721
that's one of the types that
you should almost never use is
13

14
00:00:52,721 --> 00:00:56,401
very famous for not being liked
by the typescript community
14

15
00:00:56,401 --> 00:00:59,681
because when you're writing any
it basically means "I don't want
15

16
00:00:59,681 --> 00:01:03,601
to use typescript" this can
have any types so it it's
16

17
00:01:03,601 --> 00:01:06,001
basically like not using typescript
but we're going to talk
17

18
00:01:06,001 --> 00:01:09,521
about that later and obviously
there are other types a lot
18

19
00:01:09,521 --> 00:01:13,021
more that are more advanced and
you can even create your own
19

20
00:01:13,021 --> 00:01:16,701
types but we're going to talk
about that later in the course.
20

21
00:01:16,701 --> 00:01:21,901
For now we're going to work
with the primitives. So you can
21

22
00:01:21,901 --> 00:01:26,141
go back in your project. Uh and
by the way if you want to be
22

23
00:01:26,141 --> 00:01:29,741
able to start your project very
simply what you can do is you
23

24
00:01:29,741 --> 00:01:32,221
can go in your package dot
json and you can create a
24

25
00:01:32,221 --> 00:01:35,341
start comment that is basically
going to do what we do when we
25

26
00:01:35,341 --> 00:01:39,301
start the project. So a TSC
then you're going to target the
26

27
00:01:39,301 --> 00:01:45,541
index. TS file and just write
--watch this way now you
27

28
00:01:45,541 --> 00:01:48,861
can just type NPM start and
it's going to start a project
28

29
00:01:48,861 --> 00:01:54,821
and so let's say this is closed
now if I click on go live at
29

30
00:01:54,821 --> 00:01:58,661
the bottom since now my
projects in source I have to
30

31
00:01:58,661 --> 00:02:05,541
click here to open it for now
and now I'm in the index. HTML
31

32
00:02:05,541 --> 00:02:12,621
file okay so now we can go into
our index. TS and I'm just
32

33
00:02:12,621 --> 00:02:16,021
going to transform this awesome
variable into a let so I can
33

34
00:02:16,021 --> 00:02:21,581
reassign it so to type a
variable you can do it like
34

35
00:02:21,581 --> 00:02:26,221
this I can just do colon
string like this and now my
35

36
00:02:26,221 --> 00:02:30,541
awesome variable is a string
it's a string so now I cannot
36

37
00:02:30,541 --> 00:02:33,741
do something like this okay
this is not going to work and
37

38
00:02:33,741 --> 00:02:37,501
you have to learn how to read
type script errors so it's
38

39
00:02:37,501 --> 00:02:40,701
going to say that the type a
number so the number one is not
39

40
00:02:40,701 --> 00:02:45,001
assignable to the type string
okay so you cannot put a number
40

41
00:02:45,001 --> 00:02:48,281
into a string so now you have a
validation , typescript is
41

42
00:02:48,281 --> 00:02:51,961
going to help you know when
you're doing something wrong so
42

43
00:02:51,961 --> 00:02:56,121
you cannot do that for example
you could declare a number so
43

44
00:02:56,121 --> 00:02:58,761
I'm going to call it for
example value and it's going to
44

45
00:02:58,761 --> 00:03:02,921
be a number like this and it's
going to be one okay and again  
45

46
00:03:02,921 --> 00:03:08,121
you cannot do something like
this it's not going to work so
46

47
00:03:08,121 --> 00:03:11,721
you can declare a number like
this and you can even declare
47

48
00:03:11,721 --> 00:03:16,761
for example is cool variable
boolean is going to be true
48

49
00:03:16,761 --> 00:03:22,761
like this so now on each of my
variable I have a type that is
49

50
00:03:22,761 --> 00:03:26,681
affected and I can do awesome dot
and I will have only the
50

51
00:03:26,681 --> 00:03:30,201
functions that are related to
string that you can run on a
51

52
00:03:30,201 --> 00:03:35,801
string so for example to
lowercase and now the cool
52

53
00:03:35,801 --> 00:03:40,881
thing is that you even have syntax
checking so for example if I
53

54
00:03:40,881 --> 00:03:44,881
misspell this I will have some
help and it's going to say that
54

55
00:03:44,881 --> 00:03:49,601
to local "lowerase" does not
exist on type string but maybe
55

56
00:03:49,601 --> 00:03:52,961
I meant local lowercase so it's
going to try to find the best
56

57
00:03:52,961 --> 00:03:56,481
match for what you wrote so
also this is going to work okay
57

58
00:03:56,481 --> 00:04:00,641
and you can even use the quick
fix and I'm going to  say "change
58

59
00:04:00,641 --> 00:04:04,001
spelling" and it's going to fix
it for me if I want okay so
59

60
00:04:04,001 --> 00:04:10,901
that's another cool feature of
so now example here in my
60

61
00:04:10,901 --> 00:04:15,261
paragraph if I try to inject
something else than a string I
61

62
00:04:15,261 --> 00:04:18,941
should have an error because if
you pass your mouse over inner
62

63
00:04:18,941 --> 00:04:23,181
text you're going to notice
that inner text is a string so
63

64
00:04:23,181 --> 00:04:28,421
if I try to for example put
value in it it's not going to
64

65
00:04:28,421 --> 00:04:31,861
work and again you will have an
error that says number is not
65

66
00:04:31,861 --> 00:04:36,181
assignable to type string okay
so it's important that you
66

67
00:04:36,181 --> 00:04:39,301
learn how to read type script
errors okay sometimes they are
67

68
00:04:39,301 --> 00:04:43,301
not really meaningful but most
of the time they are so it's
68

69
00:04:43,301 --> 00:04:47,061
important to understand what's
going on okay so that's how you
69

70
00:04:47,061 --> 00:04:50,741
declare a type for a variable
but now you have to know
70

71
00:04:50,741 --> 00:04:54,981
something what we have done is
not really useful so I'm going
71

72
00:04:54,981 --> 00:05:01,161
to fix that you don't really
have to explicitly tell the
72

73
00:05:01,161 --> 00:05:05,721
type here on a primitive I
could actually remove it like
73

74
00:05:05,721 --> 00:05:11,081
this and you're going to say
why what's the point so I don't
74

75
00:05:11,081 --> 00:05:14,281
need types on primitive ? No you
don't. Because Typescript is
75

76
00:05:14,281 --> 00:05:19,561
smart enough to detect what is
the type of the variable if a
76

77
00:05:19,561 --> 00:05:23,561
primitive was assigned so here
as you can see it understood
77

78
00:05:23,561 --> 00:05:26,201
that it's going to be a string
here it understood that it's
78

79
00:05:26,201 --> 00:05:30,041
going to be a number and here a
boolean so I still have my type
79

80
00:05:30,041 --> 00:05:33,161
safety okay I still cannot do
something like this: awesome
80

81
00:05:33,161 --> 00:05:37,001
equal true for example this is
not going to work so with
81

82
00:05:37,001 --> 00:05:41,161
primitives there is something
called type inference and it's
82

83
00:05:41,161 --> 00:05:44,921
basically the behavior of type
script trying to find logically
83

84
00:05:44,921 --> 00:05:49,001
what is going to be the type of
your variable okay so you don't
84

85
00:05:49,001 --> 00:05:53,241
really need to specify
especially here the type but
85

86
00:05:53,241 --> 00:05:57,641
you'll see that we will have to
do that sometimes and mostly when we
86

87
00:05:57,641 --> 00:06:01,681
will create our own types
alright But for now, we're
87

88
00:06:01,681 --> 00:06:04,401
good. You don't need to do
that. So this is actually
88

89
00:06:04,401 --> 00:06:06,881
pretty much it about
primitives, okay? You don't
89

90
00:06:06,881 --> 00:06:10,961
really have to do anything,
they're just typed by default.
90

91
00:06:10,961 --> 00:06:14,001
Thanks to the type inference of
typescript. Alright, so see
91

92
00:06:14,001 --> 00:06:17,361
you in the next one to
continue.
