Why does the JavaScript generated by the following TypeScript code generate a TypeError when executed?
class Foo {
public foo: {
bar: number
};
constructor() {
this.foo["bar"] = 123;
}
}
new Foo();
I'm compiling the code with the --strict option so I'd expect the assignment to an uninitialised variable to get caught but it doesn't.
C:\Users\Simon\test.js:4
this.foo["bar"] = 123;
^
TypeError: Cannot set property 'bar' of undefined
at new Foo (C:\Users\Simon\test.js:4:25)
at Object.<anonymous> (C:\Users\Simon\test.js:8:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
I'm using TypeScript 2.5.3.