All right.
Welcome back.
Let's finally get into things and talk about typescript now.
Why did I pick typescript.
Because there's actually many ways that we can introduce static typing to JavaScript.
There's tools like flow Elm reason AML.
And obviously typescript for example reason M.L. and Flo were created by Facebook and the developers
of Facebook and typescript by the fellows of Microsoft but they all do the same thing.
They all try and make javascript a statically type language.
Now let's talk about reason M.L. reason is based on a programming language called camel.
And like I said before it's created by Facebook to make it easy for Javascript programmers to pick up.
It's a language in its own but similar enough to javascript that it's easy to pick up and Facebook actually
uses it with some of their projects.
And currently 50 percent of their messengers front and code is written with reason so that's a popular
language coming out of Facebook.
All right.
But again I'm still not getting this what does this all mean.
Well maybe the next slide will help you
again.
All of these tools.
Their goal is to make writing javascript a little bit nicer a little less buggy and introduce static
typing and flow which is used very commonly with react projects is what we call a static type checker.
Let's start off with this one.
Flow is able to add types to our javascript by writing some code that works with flow and then putting
it through a compiler such as the baler or Babel compiler which spits out javascript and we know what
Babel does from previous sections it takes yes six code or yes seven or yes a code and changes it into
e five code so that all browsers can understand it now flow is static a static type checker which means
we're actually writing something like this at the top of our files at the top of our files.
We'll do something like dash dash at flow and flow is gonna be able to say this file has flow types
and I'm going to check it for you.
It checks the types again.
Don't worry when we talk about types you're actually you're going to learn them.
And later on videos.
But again we want to build the foundation first.
If you go back here what we actually do with flow is that it checks everything and it relies on Babel
to actually remove that ad flow and all the other types that we've entered into our code before production
before sending it to our users and flow actually comes pre-built and to create react app if we go to
the flow documentation that flow dot org.
We see that and create wrapped up.
We simply run these commands and we can start writing type checking in our code.
Again something that will cover typescript differs from flow because typescript has its own compiler.
It's not like flow that depends on Babel to remove all this extra code before spitting it into javascript
that we want to send to the front end typescript is what we call a superset of javascript that is it
adds functionality on top of javascript that means that JavaScript is TypeScript and typescript just
simply adds a few extra features on top of javascript but it also has its own compiler.
So we write typescript code which then gets run through the compiler.
And remember a compiler is just simply a machine that takes an input of some piece of code and outputs
a different piece of code.
In our case we're going to convert it from typescript to javascript that our browsers can read just
like I talked about before about reason M.L..
It has the same thing its own compiler and it's going to go through the compiler and spit out javascript
code.
The difference between typescript and reason AML is that reason is a completely separate language from
javascript on its own typescript tries to mimic javascript and grow with JavaScript.
Like I said it's a superset but reason AML is just a whole different language on its own.
It doesn't depend on any javascript changes being made in the ecosystem.
Any of that and Elm is pretty much the exact same thing as reason about its own language.
That is type safe that has its own compiler and spits out javascript so you might hear in JavaScript
land people using these tools.
The ones that you should really focus on because elm and reason AML are still fairly new.
You won't find that many jobs out there that actually request it.
It is nice to learn an interesting but again most of the time you're looking at either learning flow
or typescript.
Now the reason I'm teaching typescript instead of flow in this course is that the growth of typescript
outweighs all of the others that we've learned in this section.
All these ones now a big part of this is that angular is built with TypeScript and using typescript.
So if you're an angular developer you're already using typescript pretty much by default.
However a lot of the react community is also starting to use TypeScript and just general javascript
community is trying to get more and more used to using this and although flow was created specifically
to work with react typescript currently is overtaking its popularity.
So we wanted to learn this instead.
Plus once you learn.
Just like with most things.
Once you learn the one method it's quite easy to pick up flow and how static typing works in flow by
the way.
If you don't trust me if we take a look at a stack overflow developer survey from this year we see that
the most loved languages while we have Russ call in Python.
We have JavaScript in there but you see typescript because it's its own language.
I mean it's a superset of javascript but it's up there.
It's very very loved and it's also quite high in the wanted section so it's very very important.
And if you look anywhere everybody's really excited about typescript one quick note by the way.
Why do you think angular is such a big fan of typescript now.
This is just my opinion.
I may be wrong but if you remember I said that angular is kind of like the kitchen.
It's great for big companies like banks to make sure that their massive developer teams work within
a kitchen that has already everything defined of how to cook bread or how to cook an app typescript
adds static typing which adds an extra layer of security or an extra layer of type safety in the code.
Again expanding that kitchen to make sure that the codes or the coders the developers on the team play
within the rules.
I think that's pretty interesting.
So let's get back to the topic at hand.
As developers we must understand why we put things into our projects.
We don't want to just follow the trend because I just showed you the developer survey and everybody's
using TypeScript and just jump on the latest bandwagon as senior developers.
We must decide for ourselves what works for our project and our team and what makes sense.
So here's my outline of when to use static type checking like TypeScript your project grows larger and
larger you already have tests written and has more developers join the team.
You want the code to be self documenting and also avoid bugs as new people touch the code.
You also have the budget within the company to train new employees to learn this new language and expect
that our development cycle.
That is how fast we're able to write features and new code is gonna be slower because we're writing
more code now that's your checklist.
If that's the case then we should add typescript.
If not we shouldn't.
But in order to really understand it we actually have to write TypeScript and go through the process
so let's finally get into coding.
I'll see in the next video by.