How to customize properties in TypeScript

后端 未结 3 1023
面向向阳花
面向向阳花 2021-02-02 14:42

How do I get TypeScript to emit property definitions such as:

Object.defineProperties(this, {
    view: {
        value: view,
        enumerable: false,
                


        
3条回答
  •  独厮守ぢ
    2021-02-02 15:19

    This isn't currently supported if you want all the properties to be emitted like that. I'd recommend filing an issue at the CodePlex site with details about what your use case and requirements are.

    If you do compile with --target ES5, you can have something like this:

    class n {
        get foo() { return 3; }
        bar() { return 5; }
    }
    

    Which produces this code:

    var n = (function () {
        function n() { }
        Object.defineProperty(n.prototype, "foo", {
            get: function () {
                return 3;
            },
            enumerable: true,
            configurable: true
        });
        n.prototype.bar = function () {
            return 5;
        };
        return n;
    })();
    

提交回复
热议问题