I recently discovered an interesting phenomenon where TypeScript class properties may disappear from the transpiled output if they aren't assigned a value.
Consider this TypeScript class...
class Foo {
value: any;
}
After transpilation, it transforms into...
var Foo = (function () {
function Foo() {
}
return Foo;
}());
The Foo.value
property isn't marked as optional, so one would expect the constructor to instantiate that property, regardless of whether it's initialized with a value or not.
var Foo = (function () {
function Foo() {
Object.defineProperty(this, 'value', {});
}
return Foo;
}());
How can I achieve that desired behavior?