Why is the JavaScript code produced by this TypeScript snippet causing a TypeError
upon execution?
class Foo {
public foo: {
bar: number
};
constructor() {
this.foo["bar"] = 123;
}
}
new Foo();
Even though I'm compiling it with the --strict
option and expecting errors for uninitialized variables, the code still generates an error.
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)
The version of TypeScript being used in this case is 2.5.3.