Installation
In order to install TypeScript, you will need Node.js with NPM installed. This is very common with modern front-end web development. If you’ve followed along up to this point, you should have both of those installed on your machine. If not, you can install them with the following command:
$
npm install -g typescript
As mentioned before, the browser cannot read TypeScript so you will need to compile it. For now, let’s just learn TypeScript with one file at a time; no frameworks, no Webpack configs. Luckily, TypeScript comes pre-packaged with a compiler. You can run that with the following command.
$
tsc file-name.ts
The command tsc
stands for “TypeScript compiler. The string immediately following the command is the name of the file that you want to compile, in this case, “file-name.ts”. It’s also worth noting that TypeScript has its own file extension: .ts
for well...TypeScript.
Let’s create a new TypeScript file and compile...