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.
Reader Level:

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/

Login to add your contents and source code to this article
post comment
     
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter