In this chapter we will explain what Typescript is and how we can code a web application using Typescript.

Learning Outcomes

  • Difference between Typescript and Javascript.

  • How we convert from Typescript into Javascript.

Typescript vs Javascript

From the previous chapter we named the file we are going to type in our code script.ts

The reason the file ends in .ts instead of .js is that Angular 2 is written in a superset of Javascript called Typescript.

Typescript is the ES6 version of Javascript plus a few other Typescript only features which Angular 2 needs in order to work.

Venn Diagram of ES5/6/Typescript

You can write Angular 2 applications in either Typescript, ES6 or even ES5 Javascript.

However Angular 2 itself is written in Typescript, most examples on the web are written in Typescript, most Angular 2 jobs require you to write Typescript so this book will be teaching in Typescript.


Browsers don’t support Typescript. Browsers barely support ES6 Javascript. So how can we write our code in Typescript?

We use something called a transpiler which converts from one language to another.

We can write in Typescript and have a transpiler convert to ES6 or ES5.


To understand why is it called transpilation and not compilation in more detail see https://www.stevefenton.co.uk/2012/11/compiling-vs-transpiling/

Since most browsers don’t support ES6 features yet we are going to transpile our Typescript into ES5.


Later on in the book I’m going to show you how to transpile Typescript into Javascript locally on your computer, but since we are using plunker we are using a feature of SystemJS which lets us transpile in the browser.

If we look at the tsconfig.json file in our demo plunker we can see there are a few settings we are using to convert Typescript into Javascript.

  "compilerOptions": {
    "target": "es5", (1)
    "module": "commonjs",
    "moduleResolution": "node""sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  1. As you can see the target is set to ES5.


  • Typescript is just javascript with a few more advanced features.å

  • Browser can’t run Typescript so we first need to Transpile it into Javascript.

  • The most common version of javascript is currently ES5 so we transpile Typescript into ES5 Javascript.

results matching ""

    No results matching ""