1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
//// [declarationEmitProtectedMembers.ts]
// Class with protected members
class C1 {
protected x: number;
protected f() {
return this.x;
}
protected set accessor(a: number) { }
protected get accessor() { return 0; }
protected static sx: number;
protected static sf() {
return this.sx;
}
protected static set staticSetter(a: number) { }
protected static get staticGetter() { return 0; }
}
// Derived class overriding protected members
class C2 extends C1 {
protected f() {
return super.f() + this.x;
}
protected static sf() {
return super.sf() + this.sx;
}
}
// Derived class making protected members public
class C3 extends C2 {
x: number;
static sx: number;
f() {
return super.f();
}
static sf() {
return super.sf();
}
static get staticGetter() { return 1; }
}
// Protected properties in constructors
class C4 {
constructor(protected a: number, protected b) { }
}
//// [declarationEmitProtectedMembers.js]
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// Class with protected members
var C1 = /** @class */ (function () {
function C1() {
}
C1.prototype.f = function () {
return this.x;
};
Object.defineProperty(C1.prototype, "accessor", {
get: function () { return 0; },
set: function (a) { },
enumerable: true,
configurable: true
});
C1.sf = function () {
return this.sx;
};
Object.defineProperty(C1, "staticSetter", {
set: function (a) { },
enumerable: true,
configurable: true
});
Object.defineProperty(C1, "staticGetter", {
get: function () { return 0; },
enumerable: true,
configurable: true
});
return C1;
}());
// Derived class overriding protected members
var C2 = /** @class */ (function (_super) {
__extends(C2, _super);
function C2() {
return _super !== null && _super.apply(this, arguments) || this;
}
C2.prototype.f = function () {
return _super.prototype.f.call(this) + this.x;
};
C2.sf = function () {
return _super.sf.call(this) + this.sx;
};
return C2;
}(C1));
// Derived class making protected members public
var C3 = /** @class */ (function (_super) {
__extends(C3, _super);
function C3() {
return _super !== null && _super.apply(this, arguments) || this;
}
C3.prototype.f = function () {
return _super.prototype.f.call(this);
};
C3.sf = function () {
return _super.sf.call(this);
};
Object.defineProperty(C3, "staticGetter", {
get: function () { return 1; },
enumerable: true,
configurable: true
});
return C3;
}(C2));
// Protected properties in constructors
var C4 = /** @class */ (function () {
function C4(a, b) {
this.a = a;
this.b = b;
}
return C4;
}());
//// [declarationEmitProtectedMembers.d.ts]
declare class C1 {
protected x: number;
protected f(): number;
protected accessor: number;
protected static sx: number;
protected static sf(): number;
protected static staticSetter: number;
protected static readonly staticGetter: number;
}
declare class C2 extends C1 {
protected f(): number;
protected static sf(): number;
}
declare class C3 extends C2 {
x: number;
static sx: number;
f(): number;
static sf(): number;
static readonly staticGetter: number;
}
declare class C4 {
protected a: number;
protected b: any;
constructor(a: number, b: any);
}
|