npm install -g typescript
Since browsers don’t know about Typescript we need to convert it into something they do understand.
The process of converting Typescript into ES5 is called transpilation and we use a tool called
tsc to compile on the command line.
We can install typescript via
The preceding command will install the TypeScript compiler and add its executable
tsc to your path.
To make sure everything worked correctly type:
And it should print something like
Create a file called
Inside that file add
This generates a file called
And we can execute that file by using node, like so:
We can watch a typescript file for changes and compile it automatically with:
tsc -w hello.ts
If we want to watch all files in a directory we can just type:
If we are compiling a single file we must provide all the configuration on the command line, like so:
tsc -t ES6 -w hello.ts
-t ES6is a flag to tell typescript to transpile into ES6 instead of the default ES5.
However if we are watching a whole directory we can use a configuration file.
We can create a config file with our common settings so we don’t always have to provide them
This creates a default configuration file which we can edit later on.