Typescript is a programming language that exists as a superset of Javascript. This means that you can write plain Javascript code in Typescript with a few caveats. The advantage of Typescript is that you can use types in your code, giving you more information when writing code. For more information, see my post here. Now, let’s get Typescript on the computer.

How To Install Typescript

To install Typescript requires that you have Node.js installed on your computer. Node.js is a tool that allows you to run Javascript directly on your computer similar to C or Java. You can download it here.

Once you have Node.js installed, we should now have a command-line tool known as npm(node package manager). We can install Typescript simply by typing in npm install -g typescript and you’re done!

Understanding The Compiler

Now that you have Typescript, we are given a new command-line command called tsc. This is the Typescript compiler, which allows us to compile Typescript down to Javascript code. Here’s an example: tsc helloworld.ts This would output a new Javascript file called helloworld.js. Granted, this is not the limit of the compiler’s capabilities.

TSConfig

The compiler has different settings that can be invoked with a config file. The config file allows you to invoke certain compiler settings for your needs. Those needs, bring me to project setup.

Setting Up Your Project

Setting up a Typescript project all depends on your personal needs. However, I will give you my personal setup for most projects and a sample repository to look through to understand the flow.

You should have two main directories: src and bin. The src directory contains all of your Typescript source code; bin contains all of the outputted Javascript code. In the project directory, you should have your tsconfig setup with all the information for compilation in your project; the tsconfig is a JSON file that has various options for both the compiler and the project. That gives you the necessary setup to write code from with less hassle.

Here’s the example project directory: https://github.com/KinoAR/typescript-base

Resources

Node.js

Typescript

TSConfig

%d bloggers like this: