Typescript

Contents:
  • Introduction
  • Prerequisite & Environment set-up
  • Project Structure
  • ECMA-6 features
  • Data Types in ECMA-5 or JS
  • Custom types
  • Generic
  • Module
  • Decorators
  • Todo
Introduction:

Typescript=JavaScript + something-more

It is superset of java script.

Transpilers convert the TS to latest ECMAScript/JS version

JavaScript vs typescript

TS- statically typed language, you have to define the type before using it. So it detects the unavailable methods types before runtime moreover since typescript is a superset of JS, you can also use the dynamic nature of JS where you don’t have to define the type(by letting know ts to ignore Type), sine it has defined type it’s easy to understand.

JS- Dynamically typed language, prone to error but versatile in context of web-development being used in web-browser because sometimes we expect the type to be unknown.

Brief on JS-

Initially in 1996 Netscape navigator started using JS same time others too were using but of different version .so in 1997 ECMA standardized the JS hence JS is interchangeably called ES or ECMAScript

The latest version being used is ES6.

JS code

function func_name(value){                                 return a1+a2;                                                  }
var a1=10;
var a2=11;
var combine_value=a1+a2;
func_name(combine_value); //function call

Note:

  1. Above code is legal and returns sum of numbers

TS code :

function func_name(value: String){
return a1+a2;
}
var a1=10;
var a2=11;
var combine_value=a1+a2;
func_name(combine_value); //function call

Note:

  1. Illegal as function expects the string and we passed the number (to avoid this canuse combine_value=a1.toString()+a2)
  2. This kind of Type-check is not provided in JS

Published by

Unknown's avatar

sevanand yadav

software engineer working as web developer having specialization in spring MVC with mysql,hibernate

Leave a comment