Skip to content

Instantly share code, notes, and snippets.

@tps2015gh
Last active February 14, 2017 04:33
Show Gist options
  • Save tps2015gh/d094a0d47bf76379d32cfea1f0de2d7f to your computer and use it in GitHub Desktop.
Save tps2015gh/d094a0d47bf76379d32cfea1f0de2d7f to your computer and use it in GitHub Desktop.

Basic of Type Script Start

Basic Type

Installing

Using with Visual Studio Code

Type Script auto compile with watch ( Multiple File Watch )

Sample Code

  • a1.ts
var a = 10 ;
console.log("a 2" + a );
var i:number ; 
var str:string = "data1" ;
var str2:string = "a "+ str;
class Data1{
	data: string;
	i : number; 
	constructor( msg: string,num :number){
		this.data = msg; 
		this.i  = num;
	}
	get_msg(){
		return "Hello, "+ this.data + "/" + this.i ;
	}
	next(){
		this.i ++;
	}
}

let d1 = new Data1("msg1",10);
for( i = 1 ; i <10 ; i++){
	str = "OK " + i  + " " + d1.get_msg();
	console.log(str );
	d1.next();
}

run batch to compile with

c:\>tsc a1.ts --watch  

result a1.js is

var a = 10;
console.log("a 2" + a);
var i;
var str = "data1";
var str2 = "a " + str;
var Data1 = (function () {
    function Data1(msg, num) {
        this.data = msg;
        this.i = num;
    }
    Data1.prototype.get_msg = function () {
        return "Hello, " + this.data + "/" + this.i;
    };
    Data1.prototype.next = function () {
        this.i++;
    };
    return Data1;
}());
var d1 = new Data1("msg1", 10);
for (i = 1; i < 10; i++) {
    str = "OK " + i + " " + d1.get_msg();
    console.log(str);
    d1.next();
}

Result when run with node.js is

C:\xampp\htdocs\test_typescript>node a1.js
a 210
OK 1 Hello, msg1/10
OK 2 Hello, msg1/11
OK 3 Hello, msg1/12
OK 4 Hello, msg1/13
OK 5 Hello, msg1/14
OK 6 Hello, msg1/15
OK 7 Hello, msg1/16
OK 8 Hello, msg1/17
OK 9 Hello, msg1/18

C:\xampp\htdocs\test_typescript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment