Introducing Typescript

There is a fact that writing application in JavaScript is so hard. JavaScript is not a programming language and this makes it so hard to manipulate it specially in large application and JavaScript is never designed for large application development. Typescript is a language for application scale JavaScript development, free and open source programming language by Microsoft which compiles to plain JavaScript. Typescript is entirely dynamically typed and every JavaScript code is a valid typescript code and you can copy and Paste JavaScript code to typescript. Typescript supports tools for large-scale JavaScript applications for any browser, for any host on any OS.

As you can see in the example below (created by visual studio), Typescript adds optional types, classes, and modules to JavaScript. and essentially adds optional static typing and class-based object oriented programming.

  1. // Interface
  2. interface IPoint {
  3.     getDist(): number;
  4. }
  5.  
  6. // Module
  7. module Shapes {
  8.     // Class
  9.     export class Point implements IPoint {
  10.         // Constructor
  11.         constructor (public x: number, public y: number) { }
  12.  
  13.         // Instance member
  14.         getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); }
  15.  
  16.         // Static member
  17.         static origin = new Point(0, 0);
  18.     }
  19. }
  20.  
  21. // Local variables
  22. var p: IPoint = new Shapes.Point(3, 4);
  23. var dist = p.getDist();

Typescript extends JavaScript syntax, so any existing JavaScript programs work with Typescript without any changes. Typescript is designed for development of large applications and when translated it produces JavaScript to ensure compatibility.


Tags: TypeScript


comments powered by Disqus