In this blog we can see how to compile a typescript file automatically in  typescript .

Every time a TypeScript file is written, it must be compiled before the.js file can be produced. In order to compile the TypeScript file, we must execute the command in the console each time. The output is only visible after that.

typescript file can be compiled two different ways to perform the compilation of a TypeScript file automatically.

Using tsconfig.json file

One JSON file with the name tsconfig.json must be created and placed in the working directory.

Example:

{
“compilerOptions”: {
“target”: “es5”,
“module”: “commonjs”,
“sourceMap”: true,
}
}

Using ts. watch method :

Open terminal window in the visual studio code  and run the below method

tsc *.ts –watch 

With the TypeScript command mentioned above, it will scan the working directory or folder for any alterations, and if any are discovered, it will compile and turn the change into a JavaScript file.

For any Help or Queries Contact us on info@crmonce.com or +918096556344