TypeScript is an open-source object-oriented programming language and it’s a typed superset of JavaScript that compiles to plain JavaScript that means the code whatever we wrote in typescript will be compiled into plain JavaScript code by Typescript compiler.
The Typescript was implemented by Microsoft and the first version (0.8) of TypeScript was released in October 2012. Same as other object-oriented languages such as c#, java, etc. the typescript also offers classes, interfaces, access modifiers, etc. to build robust components.
The browsers won’t understand the code whatever we wrote in Typescript due to that you need to install the TypeScript compiler either globally or in your workspace to compile and convert TypeScript source code to JavaScript.
Generally, we will write the TypeScript code in a file with .ts
extension and the typescript compiler (TSC) will compile and convert .ts
extension file to plain JavaScript file with tsc filename.ts
command like as shown below.
The generated JavaScript file (tutlane.js
) can be included in HTML code and that will be executed by any browser.
Basically, JavaScript is not a strict type checking language which means we can assign any value to the defined variables like as shown below.
var test = "Hello world";
test = true;
test = 1001;
test = undefinded
test = ['A','B', 'C']
If you observe the above code, we defined test
variable and we are able to assign the values of different data types such as string, number, Boolean, etc. due to this, it’s difficult to maintain the large scale applications when other team members also working on the same code.
TypeScript is a strict type checking language so the compiler will associate the type to the variable at the time of variable initialization based on the value or defined type.
For example, in TypeScript the compiler will assign the string
type to the following variable based on the assigned value.
let test = 'Welcome to Tutlane';
The strict type system will help us to improve the code readability and find the errors at the compile time itself.
The TypeScript includes all the features of ES6 and ES7 versions of JavaScript and the additional features like object-oriented programming, cross-platform, etc. to build the large-scale JavaScript applications.
The following are the advantages of using TypeScript in our applications.
.d.ts
extension to provide support for external JavaScript libraries such as jQuery, AngularJS, etc. to avail the benefits of type checking, autocompletion, and member documentation.The following are the important features of TypeScript.
The TypeScript was developed and maintained by Microsoft under the Apache 2 license. The first version (0.8) of TypeScript was launched in October 2012 under the lead of Anders Hejlsberg who is the creator of c#. Now, the latest version of TypeScript is 3.7 which was released in November 2019.