How to compile TypeScript in command line?
TypeScript is the superset of JavaScript. It allows developers to use static type in JavaScript. The new ES6 functionalities can be used using TypeScript.
TypeScript can be used with React, Angular, NodeJS, etc. It is maintained by Microsoft.
To compile TypeScript into JavaScript we need to have TypeScript installed. To install TypeScript using the Node Package Manager (npm) type the following command:
$ npm install -g typescript
TypeScript files normally have a ‘.ts’ extension. To compile all the .ts files in the current directory, type:
$ tsc *.ts
We can also specify which files we want to compile:
$ tsc first.ts second.ts third.ts
We can specify the output file or directory for the new JavaScript files. To output all the new JavaScript files into a directory called ‘public’ type:
$ tsc --outDir public *.ts
We can specify a single JavaScript file for all TypeScript files. Check the following command:
$ tsc --out all.js first.ts second.ts third.ts