0
是否有任何方法使用构造函数参数public
来简化构件的装饰?Typescript:装饰构造函数公共参数?
如果我做的:
class Test{
constructor(
@decorator public b
){ }
}
那么,这是被装饰的参数,而不是成员。以下是编译的结果是:
var Test = function() {
function Test(b) {
this.b = b;
}
Test = __decorate([__param(0, decorator)], Test);
return Test;
}();
所以我发现,使我想到它的唯一方法是:
class Test{
@decorator b;
constructor(b){
this.b = b;
}
}
产生:
var Test = function() {
function Test(b) {
this.b = b;
}
__decorate([decorator], Test.prototype, 'b');
return Test;
}();
我知道这是没有那么糟糕,但重复4次相同的变量名称会让我感到恶心,因为我有很多它。