This Angular tutorial helps you get started with Angular quickly and effectively through many practical examples.

TypeScript Introduction


What is TypeScript?

  • It was designed by Anders Hejlsberg at Microsoft. Anders Hejlsberg is also designer of C# language.
  • TypeScript is a superset of JavaScript.
  • Object-Oriented language - It is object-oriented language with classes, interfaces and statically typed programming like C# or Java.
  • You will need a compiler to compile typescript code and generate the code in the JavaScript file(js file).
  • TypeScript is the ES6 version of JavaScript with some additional programming language features.
  • A TypeScript code is written in a file which have.ts extension.
  • TypeScript supports JavaScript libraries - It allows the developers to use existing JavaScript code with the TypeScript. Here, we can use all of the JavaScript frameworks, tools, and other libraries easily to develop applications.
  • JavaScript is TypeScript - The code written in JavaScript with valid .js extension can be converted to TypeScript by changing the extension from .js to .ts and compiled with other TypeScript files.
  • TypeScript is portable - Execute on any browsers, devices, or any operating systems.
  • DOM Manipulation - To manipulate the DOM for adding or removing elements similar to JavaScript.

TypeScript
TypeScript and ECMAScript6(ES6)

JavaScript ES6 (also known as ECMAScript 2015 or ECMAScript 6) is the latest version of JavaScript that was introduced in 2015. ECMAScript set the standard that JavaScript programming language uses. ECMAScript provides the specification on how JavaScript programming language should work. TypeScript is aligned with the ECMAScript6 specification or standard which JavaScript programming language follows.

ECMAScript6

How to use TypeScript?

A TypeScript code is written in a file with .ts extension and then compiler convert the ts file into JavaScript (JS file) using the compiler. the command tsc <filename>.ts compiles the TypeScript code into a plain JavaScript file.

TypeScript compiler
 
Compile TypeScript to JavaScript

Syntax: var Name:string = "Rohatash"
console.log(Name)

After compiling, it generates the following JavaScript code:

var Name= "Rohatash";
console.log(Name); 

Type Script Features

  TypeScript Features
 
Cross-Platform

TypeScript can run on any platform that JavaScript runs on. The TypeScript compiler named tsc is written in TypeScript. The TypeScript compiler can be installed on any Operating System such as Windows, macOS, and Linux.

Object-Oriented Language

TypeScript provides powerful features as object-oriented languages such as Classes, Interfaces, and Modules etc. You can write fully object-oriented code for client-side as well as server-side development.

Static type-checking

TypeScript uses static typing. This is done using type annotations. It helps type checking at compile time. Thus, you type the code in typescript without compiling or running the code you can find errors. Additionally, using the type inference mechanism, if a variable is declared without a type, it will consider that based on its value.

Optional Static Typing

TypeScript static typing is optional, when we assign any value to the variable. At the compilation time typescript will not show any error.

DOM Manipulation

Like JavaScript, TypeScript can be used to accessed and manipulate the DOM.

ES 6 Features

TypeScript includes most of the features which planned ECMAScript 2015 (ES 6, 7) such as class, interface, Arrow functions etc.


Prev Next