In this lecture, we're going to install a compiler for TypeScript.
That sounds strange, doesn't it?
Normally we would be able to write JavaScript right away.
We wouldn't need to worry about compiling the code ourselves, since the browser will interpret our
code for us.
However, it's a different story with TypeScript.
Most browsers don't support TypeScript.
Therefore, we need to compile our TypeScript code into JavaScript after we we've compiled it to JavaScript.
We'll be able to run our code in the browser or node.
Luckily, this process is painless.
In the resource section of this lecture, I provide a link to TypeScript.
Everything you'd like to learn about TypeScript can be found here on this page.
It'll recommend some installation methods.
TypeScript can be installed with 21:00.
Let's give it a try.
Copy the command from the documentation.
Inside the command line, I will paste and run the command.
If you're on a Mac or Linux, you may need to add the pseudo command before running it.
It'll give you proper permissions for installing packages.
Otherwise, running the command, as is, will work fine for this installation.
I'm working in the same directory we were in in the last lecture.
This installation should take a few seconds.
We're installing TypeScript locally.
We have the option of installing it globally, but that won't be necessary.
It's enough to have it installed locally.
After installing TypeScript, we can begin to write TypeScript code.
The first step for writing TypeScript is to create a file in our project.
We're going to rename the Example D.J.s file by changing the extension to its.
This is short for TypeScript after changing the file type.
We've written our first TypeScript file.
As I've said before, TypeScript syntax is the exact same as JavaScript syntax.
Every syntax feature from JavaScript is supported in TypeScript.
Therefore, we don't need to learn an entirely new set of syntax rules after we've written our TypeScript
code.
The next step is to compile it into JavaScript.
We can use the compiler we installed to help us with that step and the command line we can run TypeScript
by adding the NPCs CSC Command.
NTPC's is a command created by 21:00 in the Node.js ecosystem.
Some packages add commands to the command line.
The command allows us to run those commands that come from those packages.
For example, TSC is a command defined by the TypeScript package.
21:00 will take care of searching for the command in the TypeScript package.
After typing the command, we need to provide the files name we want to compile from TypeScript to JavaScript.
Let's pass an example.
Dots afterward will run the command.
After a few moments, the command will finish running.
So what happened?
If we look in our project directory, we'll find a new file has been generated called Example Dogs.
Let's take a look inside.
We have the exact same code we had before.
The problem we had before persisted at this point.
It doesn't feel like TypeScript isn't helping us in the next couple of lectures.
We're going to explore the syntax added by TypeScript.
By doing so, we'll be able to fix our issue.
I'll see you there.