This lesson has been retired.
Become a member
to unlock all features

    Installing TypeScript and Running the TypeScript Compiler (tsc)

    John LindquistJohn Lindquist

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



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson


    00:00 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.

    00:17 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.

    00:47 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.

    01:04 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.

    01:31 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.

    01:48 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.