TypeScript Tutorial for Beginners

Introduction to TypeScript

TypeScript is developed and maintained by Microsoft. It is an open-source object-oriented language. TypeScript is a superset of JavaScript. Using TypeScript, Javascript can be written in any form. TypeScript is used to compile plain JavaScript. It is developed under Anders Hejlsberg.

TypeScript was first released in October 2012.

Features of TypeScript

  • TypeScript is designed for development of large applications and transcompiles to JavaScript.
  • TypeScript is purely object-oriented, so it has classes and interfaces which are typed like C# or Java. Angular 2.0 is a framework of JavaScript written in TypeScript.
  • TypeScript is used to develop JavaScript applications for both client-side and server-side execution. It provides many options like default TypeScript checker to compile. The TypeScript compiler compiles the file into JavaScript. It is licensed under the Apache 2 License.
  • TypeScript supports definition files like C++ header files, which contain information of existing JavaScript libraries.
  • In TypeScript, third-party header files libraries are also present such as jQuery, MongoDB, and D3.js.

History of TypeScript

TypeScript launched version 0.8 in October 2012. It took 2 years for Anders Hejlsberg, Delphi and Turbo Pascal to develop TypeScript at Microsoft. The language was praised By a Mexican programmer, Miguel de Icaza.

In 2013, version 0.9 was launched with new features. The TypeScript was supported by other IDEs, such as Eclipse using plug-in provided by Palantir Technologies. It was also supported by several text editors such as Sublime, Vim and Emacs.

In 2014, version 1.0 was released. In July 2014, a new compiler was developed. New compiler brings five times gains in performance. The source code for TypeScript was originally hosted by CodePlex, was shifted to Github.

In 2016, version 2.0 was released, with several features, like the ability to optionally prevent variables from being assigned null values.

TypeScript and ECMAScript

ECMAScript is standard specification of a scripting language. There are several versions of ECMAScript. “Harmony” is the version 6. TypeScript uses ECMAScript6 specification. TypeScript uses basic language features from the ECMAScript5 specification. TypeScript has features like Modules and class-based orientation with the EcmaScript 6 specification.

TypeScript and ECMAScript


Type System is used to represent different types of values which are supported by the language. It is used to check validity of supplied value before storing or manipulating the program.

Following are the types of data types in TypeScript:

data types in TypeScript

The Any type

It is the super type of all types in TypeScript. It is also denoted as dynamic type.

Built-in types

Data type Keyword Description
Number number Double precision 64-bit floating point values. It can be used to represent both, integers and fractions.
String string Represents a sequence of Unicode characters.
Boolean boolean Represents logical values, true and false.
Void Void Used on function return types to represent non-returning functions.
Null Null Represents an intentional absence of an object value.
Undefined undefined Denotes value given to all uninitialized variables.

User-defined Types

It includes Enumerations (enums), classes, interfaces, arrays, and tuple.

Components of TypeScript

There are three components in TypeScript:

  1. Language

It checks syntax, keywords, and type annotations.

  1. The TypeScript Compiler

It is used to convert instructions written in TypeScript to its JavaScript.

  1. The TypeScript Language Service

It has an additional layer of core compiler that are editor-like applications.

TypeScript Language Service

Features of TypeScript

  1. TypeScript is just JavaScript

TypeScript starts with JavaScript and ends with JavaScript.

  1. TypeScript supports other JS libraries.

Compiled TypeScript can be used from any JavaScript code.

  1. JavaScript is TypeScript.

This means that .js file can be renamed to .ts and compiled with other TypeScript files.

  1. TypeScript is portable.

It is portable in browsers, devices, and operating systems.

Advantage of TypeScript

  1. Code written in TypeScript is more predictable due to static typing and also it is easy to debug.
  2. Easy to organize code for very large and complicated apps, due to modules, namespaces and strong OOP support.
  3. TypeScript compiles JavaScript which catches all kinds of error before reaching runtime.
  4. Angular2 framework is written in TypeScript.

Disadvantage of TypeScript

  1. Learning Curve: Developing Front-end with all types of frameworks and technologies is hard. Not every JavaScript developers know TypeScript. The learning curve will make team work hard. So if a team wants to go in this way, everyone should have a good understanding of TypeScript.
  1. Needs Development Tools: Visitors do not require any plugin to run TypeScript but developers require special tools in editor or IDE.
  1. Cannot easily be edited by Content Management Systems (CMS): If Content Management Systems is used in developing a website, .css style files, and .js script files can be edited in the admin portal but in TypeScript, it is not easy to edit. You need extra plugins to edit.

Also Read: Commonly Asked TypeScript Interview Questions and Answers for Fresher