Introduction
In this post, we are going to learn how to compile our TypeScript file automatically.
As we know, after writing any TypeScript file, we need to compile it every time and based on that, the .js file will be generated. So, every time, we should compile the TypeScript file by writing the command in the console. Then only can we see the output.
But I'm going to share two different ways to perform the compilation of a TypeScript file automatically. Let's see these two ways with an example.
Using tsconfig.json file
For that, we need to create one JSON file named tsconfig.json into our working directory. The code will look like below.
- {
- "compilerOptions": {
- "target": "es5",
- "module": "commonjs",
- "sourceMap": true,
- }
- }
- "watch":true
You can find the complete code for tsconfig.json below.
- {
- "compilerOptions": {
- "target": "es5",
- "module": "commonjs",
- "sourceMap": true,
- "watch":true
- }
- }
Another way of automating the TypeScript compilation is by using command line interface or the Command Prompt.
The second way is pretty simple to achieve; we just need to write a single line to watch any changes in our TypeScript file.
Just open a terminal window and write the following command.
- tsc *.ts --watch
After executing the above command, you will get a compilation message somewhat like,
Conclusion
So, using these two ways, you can make the compilation task automatic.
Follow my other TypeScript posts -
I hope it will help you some day. Thanks for reading.

Mahesh VermaPosted Apr 6, 2018, 6:33 AM
Great explanation....thanks for sharing.....
Naresh SinghalPosted Apr 6, 2018, 6:22 AM
Fantastically explained Manav Pandya