Description
I just confirmed in the TS Playground that the following TS:
class Foo {
get bar() { return true;}
}
Produces this JS:
var Foo = (function () {
function Foo() {
}
Object.defineProperty(Foo.prototype, "bar", {
get: function () { return true; },
enumerable: true,
configurable: true
});
return Foo;
})();
This MDN link confirms that, for Object.definedProperty
accessors:
• enumerable: Defaults to false.
• configurable: Defaults to false.
Clearly the generated code is overriding the default values for these keys.
Plowing through the ES6 spec is not something I do. So I’m not sure that ES6 hasn’t changed the defaults. But I’d be surprised.
Now one of the things I miss in TS/ES6 class definitions is the ability to control these keys. It is also not easy to embellish a class with defined properties later … properties that might have non-default definitions
But that’s not my point or my question … which is, why is TS deviating from the defaults?
I get why I’d want the property to be enumerable most of the time – strange that the spec defaults to false. I don’t understand why I should want it to be configurable (maybe because I don't like something about the property TS generated for me?).
In any case, I don’t get how TS (or ES6) gets away with changing the ES5 defaults.