/typescript/

TypeScript part 8 (array, tuples, enum)

2017-03-04 11:36:30

TypeScript

let array1 = ["lorem", "ipsum"];
let array2: string[] = ["lorem", "ipsum"];

let array3 = ["string", 1, true];
let array4: any = ["string", 1, true];

let array5 = [1, 2, 3];
let array6: number[] = [1, 2, 3];

let tuples1: [string, number] = ["Lorem", 16];
let tuples2: [string, string] = ["Lorem", "Ipsum"];

enum Color {WHITE, RED, BLUE}
let myColor1 = Color.WHITE; //1
let myColor2 = Color.RED; //2
let myColor3 = Color.BLUE; //3

enum Color2 {WHITE = 101, RED = 102, BLUE = 103}
let myColor21 = Color.WHITE; //101
let myColor22 = Color.RED; //102
let myColor23 = Color.BLUE; //103

JavaScript

var array1 = ["lorem", "ipsum"];
var array2 = ["lorem", "ipsum"];
var array3 = ["string", 1, true];
var array4 = ["string", 1, true];
var array5 = [1, 2, 3];
var array6 = [1, 2, 3];
var tuples1 = ["Lorem", 16];
var tuples2 = ["Lorem", "Ipsum"];
var Color;
(function (Color) {
    Color[Color["WHITE"] = 0] = "WHITE";
    Color[Color["RED"] = 1] = "RED";
    Color[Color["BLUE"] = 2] = "BLUE";
})(Color || (Color = {}));
var myColor1 = Color.WHITE; //1
var myColor2 = Color.RED; //2
var myColor3 = Color.BLUE; //3
var Color2;
(function (Color2) {
    Color2[Color2["WHITE"] = 101] = "WHITE";
    Color2[Color2["RED"] = 102] = "RED";
    Color2[Color2["BLUE"] = 103] = "BLUE";
})(Color2 || (Color2 = {}));
var myColor21 = Color.WHITE; //101
var myColor22 = Color.RED; //102
var myColor23 = Color.BLUE; //103