[MUSIC]
>> What is TypeScript?
>> TypeScript, it's a superset of the JavaScript language.
It's still plain old JavaScript.
You can write plain JavaScript
exactly as you're writing today in .js files,
but instead of using .js as the file extension,
you change it to .ts, which is TypeScript.
What this does is it then gives the TypeScript Compiler,
which is a thing that will process the language,
but you might be familiar with other sorts of
compiler aspects to JavaScript like Babel,
if you wanted to use features that are not
supported in all JavaScript runtimes,
you want something that works everywhere.
The similarity with TypeScript.
We can take our superset of
the JavaScript language being TypeScript,
which allows us to do type annotations,
say we know that something's always going to contain a number,
so we explicitly state that it can only contain a number.
If we would ever try and assign a string to that variable,
which is perfectly legitimate in JavaScript,
you can convert something from
a number to a string inside of the same variable,
the TypeScript Compiler will say, "Hang on a second.
Are you sure you wanted to do that?" and give you an error.
This kind of compiler safety,
being able to understand the data types that we're working with,
the shapes of objects,
means that as we build out more and more complex applications,
we can understand how data is being used in that application,
what the shape of that data is,
and then make sure that we're
using it the way that it was intended to be used.
We're not passing a number where we expected a string or
a function when instead of we wanted
an object and so on and so forth.
>> Yeah. It's definitely one of those things.
The great part about JavaScript
is that it lets you do whatever it is that you
want to do and just trust
that you know what it is that you're talking about.
Of course, the bad thing is is that it will let you do whatever it
is that you want to do and
trust that you know what you're talking about.
I very rarely, if ever,
know what it is that I'm talking about.
>> Yeah.
>> One of the other things I really like about TypeScript,
and you touched on it a bit with Babel,
is it also then helps smooth over some of
the edges when it comes to JavaScript.
I've been in web dev for about as long as you have.
If you would've told me back then that we'd be doing the things
with JavaScript that we're now doing with them today,
I'd have looked at you like you had three heads,
that it's just not possible.
In a lot of ways, it's still
not that we are
using JavaScript in a lot of ways it wasn't designed for,
but TypeScript really does help smooth out some of those edges.
>> Sure. At least, in my experience,
it's made it a lot easier to build applications that are a lot
more complex than might
have larger dev teams that are working across them.
Things like that is where I find TypeScript
really makes its value proposition strong.
It might not be right if you're just a single person working
on an application that's got half a dozen files,
there's definitely value, I'll also do it that way.
But if you're working in a team
and you've got people that are working on
different shared components or
they're working on different service layers,
even you can build a client and server application,
where you've got like a node.js back-end and a React front-end,
they're able to share the data types
between those so that you know
that when you're doing a call to
a REST endpoint or through a GraphQL endpoint,
here's the shape of the data that you're getting back.
We've just got that same set of type shared back and forth,
so we can enforce that the client
respects what the server is sending and vice versa.
>> One hundred percent.
The way that I try to convince everybody
that they should be using TypeScript is just,
let me create this interface for
you and then show you how this works.
That ability to be able to
define those types and be able to share them is
such a huge thing and it makes you so much more productive,
because then you don't have to stop and remember,
did I call it user?
Did I call it username?
Did I call it userId?
If I called it userId, was it lowercase id,
was it capital I,
lowercase d? You don't have to
worry about any of that because the interface,
the type will tell you what that is.