Reader Level:
ARTICLE

Let's Start With TypeScript

Posted by Nitin Bhardwaj Articles | TypeScript October 05, 2012
In this article I have described the basics of programming in TypeScript in Visual Studio 2012 with an example.
  • 0
  • 0
  • 2501

Basic of TypeScript

TypeScript is a syntactic enhancement for JavaScript. The TypeScript syntax is a superset of Ecmascript 5 (ES5) syntax. Every JavaScript program is also a TypeScript program. The TypeScript compiler performs only file-local transformations on TypeScript programs and does not re-order variables declared in TypeScript.

The following example shows the basics of TypeScript programs. The example just prints "Hello" in the HTML document.

Coding

simpledemo.ts

class simpledemo {

   constructor(public greeting: string) { }

   greet() {

       return"<h1>" + this.greeting + "</h1>";

   }

};

var simple = new simpledemo("Hello, C-sharpcorner user....!");

var str = simple.greet();

document.body.innerHTML = str;

 

simpledemo.html

<!DOCTYPEhtml>

<html>

  <head><title> TypeScript simpledemo </title></head>

  <body>

    <scriptsrc="app.js"></script>

  </body>

</html>

 

app.js

var simpledemo = (function () {

    function simpledemo(greeting) {

        this.greeting = greeting;

    }

    simpledemo.prototype.greet = function () {

        return"<h1>" + this.greeting + "</h1>";

    };

    return simpledemo;

})();

; ;

var simpledemo = new simpledemo("Hello, C-sharpcorner user...!");

var str = simpledemo.greet();

document.body.innerHTML = str;

 

Output

 

simple-demo.type-script.gif

Reference By

http://www.typescriptlang.org/

COMMENT USING