What is 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.
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.
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
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.