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 especially 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 the visual studio), Typescript adds optional types, classes, and modules to JavaScript. and essentially adds optional static typing and class-based object-oriented programming.

 

// Interface
interface IPoint {
    getDist(): number;
}

// Module
module Shapes {
    // Class
    export class Point implements IPoint {
        // Constructor
        constructor (public x: number, public y: number) { }

        // Instance member
        getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); }

        // Static member
        static origin = new Point(0, 0);
    }
}

// Local variables
var p: IPoint = new Shapes.Point(3, 4);
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 and I'm spending a lot of my time on architecture subject. Since 2008, I've been as a developer for companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the&nb Read More

Post Tags
Pending Blog Posts
Strategic design
Factory Pattern
time out pattern in ajax
Selectors in Jquery
Peridic pattern
How to use PagedList In asp.net MVC
Redis as a cache server
Domain driven design VS model driven architecture
How to query over Icollection<> of a type with linq
What's the DDD-lite?
comments powered by Disqus