Compiling manually using the TypeScript compiler

Now let’s try to use tsc (the TypeScript compiler) to manually compile our code.
Go back to the Terminal and run tsc:

As you can see, there are many options. You can list all the available options using tsc --all. We'll discover some of those as we go about building cool applications together but, for now, let's focus on the task at hand: compiling a single file. You can do this by executing tsc hello-world.ts.

If all goes well, you should see nothing. But TypeScript should have transpiled your code to JavaScript.

By convention, TypeScript generates a .js file with the same name as the input file, right next to it. If you list the directory contents, you should see the newly added file:

$ ls
total 2.0K
drwxr-xr-x 1 dsebastien 197121 0 Sep 25 15:42 .
drwxr-xr-x 1 dsebastien 197121 0 Sep 25 14:07 ..
drwxr-xr-x 1 dsebastien 197121 0 Sep 25 14:16 .vscode
-rw-r--r-- 1 dsebastien 197121 100 Sep 25 15:42 hello-world.js <-----
-rw-r--r-- 1 dsebastien 197121 104 Sep 25 15:29 hello-world.ts

Let's see what TypeScript has generated for us:

var hello = "Hello world";
function say(something) {
console.log(something);
}
say(hello);

This is, apart from whitespace, the exact same code. Captain Obvious again here, but indeed, since we have given JavaScript code as input to TypeScript's compiler, it didn't have much to do for us. This was just a tease; now let's make use of the TypeScript type system!