var isDone = true ; var height = 6 ; var name = 'test' ; var list = [ 1 , 2 , 3 ] ; enum Color { Red , Green , Blue } var c = Color . Green ; var notSure = 4 ; notSure = 'maybe a string' ; notSure = false ; var anotherList = [ 1 , true , 'free' ] ; function warnUser ( ) { alert ( 'This is my warning message' ) ; } function add ( a , b ) { return a + b ; } function sayHello ( name ? ) { if ( name ) { console . log ( 'Hello ' + name + '!' ) ; } console . log ( 'Hello' ) ; } var x = 10 ; var y = 20 ; add ( x , y ) ; function takesCallback ( cb ) { return cb ( new Error ( 'Boom!' ) ) ; } takesCallback ( function ( err ) { console . log ( err . message ) ; } ) ; interface MyInterface { value : string ; method ( ) : number ; ( ) : boolean ; } interface Foo { x : number ; y : number ; } var foo = { } as Foo ; foo . x = 10 ; foo . y = 10 ; var bad = { x : 10 } as any as string ; bad . toUpperCase ( ) ; type HelloWorld = string ; function print ( ) { return 'hello world' ; } print ( ) . toUpperCase ( ) ; function getLabel ( obj ) { return obj . label ; } type LabelObj = { label : string ; } ; interface Animal { legs : number ; } interface Dog extends Animal { bark : string ; } function typeGuard ( obj ) { return typeof obj . bark === 'string' ; } var dog = { legs : 4 , bark : 'woof!' } ; if ( typeGuard ( dog ) ) { alert ( 'It\'s a dog! ' + dog . bark ) ; } function identity < T > ( arg ) { return arg ; } function arrify < T > ( arr ) { if ( Array . isArray ( arr ) ) { return arr ; } return [ arr ] as T [ ] ; } interface Map < T > { [ key ] : T ; } var dictionary = { } ; dictionary [ name ] = name ; var value = 'test' ; console . log ( value . length ) ; function extend < A , B > ( a , b ) { Object . keys ( b ) . forEach ( key => { ( a as any ) [ key ] = ( b as any ) [ key ] ; } ) ; return a as A & B ; } function makeDogFromAnimal ( animal ) { return extend ( animal , { bark : 'woof woof woof' } ) ; } var tuple = [ 'hello' , 10 ] ; console . log ( tuple [ 0 ] . substr ( 1 ) ) ; import * as TS from 'typescript' ; declare function require ( module ) ; function eventually ( ) { var ts = require ( 'typescript' ) ; } class Foo { bar : string ; } function create < T > ( Clazz ) { return new Clazz ( ) ; } var result = create ( Foo ) ; class Calculator { constructor ( protected value = 0 ) { } result ( ) { return this . value ; } add ( operand ) { this . value += operand ; return this ; } subtract ( operand ) { this . value -= operand ; return this ; } } var x = new Calculator ( 10 ) . add ( 5 ) . result ( ) ;