Sample file download

Sample TypeScript file (.ts)

TypeScript is a language that compiles to JavaScript.

Here is the file type (wrongfully recognised as C++):

$ file sample.ts
sample.ts: C++ source, ASCII text

To compile the file:

$ tsc sample.ts

Which generates the following JS:

$ cat sample.js
var HelloWorld = (function () {
    function HelloWorld(greeting) {
        this.greeting = greeting;
    }
    HelloWorld.prototype.greet = function () {
        return "<h1>" + this.greeting + "</h1>";
    };
    return HelloWorld;
}());
;
var helloWorld = new HelloWorld("Hello, world!");
document.body.innerHTML = helloWorld.greet();

Sample TypeScript file: download here.

More information on TypeScript

Tags:

Top Site Counter