Ehsan Ghanbari

Experience, DotNet, Solutions

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. }
  6. // Module
  7. module Shapes {
  8.     // Class
  9.     export class Point implements IPoint {
  10.         // Constructor
  11.         constructor (public x: number, public y: number) { }
  13.         // Instance member
  14.         getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); }
  16.         // Static member
  17.         static origin = new Point(0, 0);
  18.     }
  19. }
  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.

About Me

Ehsan Ghanbari

Hi! my name is Ehsan. I'm a developer, passionate technologist, and fan of clean code. I'm interested in enterprise and large-scale applications architecture and design patterns. I spend a lot of time on software architecture. Since 2008, I've been as a developer for different companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the past years, Read More

Post Tags
Pending Blog Posts
using Elmah in MVC4
Using FluentSecurity in MVC
Strategic design
Factory Pattern
time out pattern in ajax
Redis as a cache server
How to use PagedList In MVC
Multiple submit buttons in MVC
Domain driven design VS model driven architecture
What's the DDD-lite?
comments powered by Disqus