mercredi 26 octobre 2016

Decorate all properties with type metadata in TypeScript

Given this code:

class Foo {
    text: String;
}

TypeScript will produce this JavaScript:

var Foo = (function () {
    function Foo() {
    }
    return Foo;
}());

But if I decorate text with any decorator, such as function bar(t, k) {} like this:

class Foo {
    @bar text: String;
}

TypeScript will produce:

var Foo = (function () {
    function Foo() {
    }
    __decorate([
        bar, 
        __metadata('design:type', String)
    ], Foo.prototype, "text", void 0);
    return Foo;
}());

That is, it decorates text with the bar function and with design:type metadata. This is great, but I'd like to instruct TypeScript to decorate all properties with design:type metadata, without the need of a bogus decorator like @bar.

Is it possibile in the latest TypeScript?





Aucun commentaire:

Enregistrer un commentaire