Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 959 of the free egghead.io lessons, plus get TypeScript content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Installing TypeScript and Running the TypeScript Compiler (tsc)

1:59 TypeScript lesson by

This lesson shows you how to install TypeScript and run the TypeScript compiler against a .ts file from the command line.


egghead.io comment guidelines

Avatar
egghead.io

This lesson shows you how to install TypeScript and run the TypeScript compiler against a .ts file from the command line.

Avatar
bachofner

Hi, thanks for the course, it is really what I needed. May I ask which theme are you using for vsc? :)

To install the TypeScript compiler, you use npm, and type npm install -g typescript. That will download and install the compiler. Once that's done, you can test it with tsc -v, so TypeScript compiler version, and will print the version number.

Now, I have the compiler installed. I'll create a new file, call it app.ts. I'll try to class it and call it Person. Save that, and come over here and say tsc app.ts. This will compile our app TypeScript file for us. You can see the output here is app.js. It converted what we have as a class defined here to what a class would be defined as in ES5.

If you want to output to a different file, you do --out and say something like bundle.js, and then pass in the file you want to compile. I'll hit Enter. You'll see now we get a bundle, which has the same output as our app.js had before.

Lastly, if you want to continuously watch with -w, or --watch, then you can watch, give it an Out-File of bundle.js, pass in your file of app.ts. Once I hit Enter, you can see that it's watching for file changes. If I come over here, and I add name equals John, I hit Save, you can see it triggered a File Change Detected.

If I check my bundle, you'll see it added this as John. Let's split these, and make this full size so we can see this in action. I'll change this to Sally. Hit save. You can see it automatically updates my file over here.

The TypeScript compiler has many, many more options, which you can find under Help. You probably won't use them in the command line. You'll probably use a configuration file to define all of these.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?