module a { let foo = { } ; foo [ 'Hello' ] = 'World' ; console . log ( foo [ 'Hello' ] ) ; } module b { class Foo { constructor ( public message ) { } ; log ( ) { console . log ( this . message ) ; } } let foo = { } ; foo [ 'Hello' ] = new Foo ( 'World' ) ; foo [ 'Hello' ] . log ( ) ; } module c { let obj = { toString ( ) { console . log ( 'toString called' ) ; return 'Hello' ; } } ; let foo = { } ; foo [ obj ] = 'World' ; console . log ( foo [ obj ] ) ; console . log ( foo [ 'Hello' ] ) ; } module d { let foo = [ 'World' ] ; console . log ( foo [ 0 ] ) ; } module e { let obj = { toString ( ) { return 'Hello' ; } } ; let foo = { } ; foo [ obj ] = 'World' ; foo [ obj . toString ( ) ] = 'World' ; } module f { let obj = { message : 'Hello' } ; let foo = { } ; foo [ obj ] = 'World' ; console . log ( foo [ "[object Object]" ] ) ; } module f { console . log ( ( 1 ) . toString ( ) ) ; console . log ( ( 2 ) . toString ( ) ) ; } module g { let foo = { } ; /**
     * Must store stuff that conforms the structure
     */ /** Ok */ foo [ 'a' ] = { message : 'some message' } ; /** Error: must contain a `message` or type string. You have a typo in `message` */ foo [ 'a' ] = { messages : 'some message' } ; /**
     * Stuff that is read is also type checked
     */ /** Ok */ foo [ 'a' ] . message ; /** Error: messages does not exist. You have a typo in `message` */ foo [ 'a' ] . messages ; } module mustConform { /** Okay */ interface Foo { [ key ] : number ; x : number ; y : number ; } /** Error */ interface Bar { [ key ] : number ; x : number ; y : string ; } } module mustConform2 { interface Foo { [ key ] : number ; x : number ; } let foo = { x : 1 , y : 2 } ; foo [ 'x' ] ; let x = 'x' ; foo [ x ] ; } module dual { interface ArrStr { [ key ] : string | number ; [ index ] : string ; length : number ; } } module jsland { interface NestedCSS { color ? : string ; [ selector ] : string | NestedCSS ; } const example = { color : 'red' , '.subclass' : { color : 'blue' } } ; const failsSilently = { colour : 'red' , } ; } module better { interface NestedCSS { color ? : string ; nest ? : { [ selector ] : NestedCSS ; } ; } const example = { color : 'red' , nest : { '.subclass' : { color : 'blue' } } } ; const failsSilently = { colour : 'red' , } ; }