Added protected conformance tests

This commit is contained in:
Mohamed Hegazy
2014-09-23 11:22:38 -07:00
parent 5a33707e38
commit a6fdad1e97
61 changed files with 3782 additions and 8 deletions
@@ -0,0 +1,99 @@
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(22,12): error TS1029: 'private' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(23,12): error TS1029: 'private' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(24,12): error TS1029: 'private' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(25,12): error TS1029: 'private' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(27,12): error TS1029: 'protected' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(28,12): error TS1029: 'protected' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(29,12): error TS1029: 'protected' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(30,12): error TS1029: 'protected' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(32,12): error TS1029: 'public' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(33,12): error TS1029: 'public' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(34,12): error TS1029: 'public' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(35,12): error TS1029: 'public' modifier must precede 'static' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(40,13): error TS1028: Accessibility modifier already seen.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(40,20): error TS1028: Accessibility modifier already seen.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(41,12): error TS1028: Accessibility modifier already seen.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(42,13): error TS1028: Accessibility modifier already seen.
tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts(43,12): error TS1028: Accessibility modifier already seen.
==== tests/cases/conformance/classes/propertyMemberDeclarations/accessibilityModifiers.ts (17 errors) ====
// No errors
class C {
private static privateProperty;
private static privateMethod() { }
private static get privateGetter() { return 0; }
private static set privateSetter(a: number) { }
protected static protectedProperty;
protected static protectedMethod() { }
protected static get protectedGetter() { return 0; }
protected static set protectedSetter(a: number) { }
public static publicProperty;
public static publicMethod() { }
public static get publicGetter() { return 0; }
public static set publicSetter(a: number) { }
}
// Errors, accessibility modifiers must precede static
class D {
static private privateProperty;
~~~~~~~
!!! error TS1029: 'private' modifier must precede 'static' modifier.
static private privateMethod() { }
~~~~~~~
!!! error TS1029: 'private' modifier must precede 'static' modifier.
static private get privateGetter() { return 0; }
~~~~~~~
!!! error TS1029: 'private' modifier must precede 'static' modifier.
static private set privateSetter(a: number) { }
~~~~~~~
!!! error TS1029: 'private' modifier must precede 'static' modifier.
static protected protectedProperty;
~~~~~~~~~
!!! error TS1029: 'protected' modifier must precede 'static' modifier.
static protected protectedMethod() { }
~~~~~~~~~
!!! error TS1029: 'protected' modifier must precede 'static' modifier.
static protected get protectedGetter() { return 0; }
~~~~~~~~~
!!! error TS1029: 'protected' modifier must precede 'static' modifier.
static protected set protectedSetter(a: number) { }
~~~~~~~~~
!!! error TS1029: 'protected' modifier must precede 'static' modifier.
static public publicProperty;
~~~~~~
!!! error TS1029: 'public' modifier must precede 'static' modifier.
static public publicMethod() { }
~~~~~~
!!! error TS1029: 'public' modifier must precede 'static' modifier.
static public get publicGetter() { return 0; }
~~~~~~
!!! error TS1029: 'public' modifier must precede 'static' modifier.
static public set publicSetter(a: number) { }
~~~~~~
!!! error TS1029: 'public' modifier must precede 'static' modifier.
}
// Errors, multiple accessibility modifier
class E {
private public protected property;
~~~~~~
!!! error TS1028: Accessibility modifier already seen.
~~~~~~~~~
!!! error TS1028: Accessibility modifier already seen.
public protected method() { }
~~~~~~~~~
!!! error TS1028: Accessibility modifier already seen.
private protected get getter() { return 0; }
~~~~~~~~~
!!! error TS1028: Accessibility modifier already seen.
public public set setter(a: number) { }
~~~~~~
!!! error TS1028: Accessibility modifier already seen.
}
@@ -0,0 +1,59 @@
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(3,9): error TS2379: Getter and setter accessors do not agree in visibility.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(6,17): error TS2379: Getter and setter accessors do not agree in visibility.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(11,19): error TS2379: Getter and setter accessors do not agree in visibility.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(14,17): error TS2379: Getter and setter accessors do not agree in visibility.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(19,19): error TS2379: Getter and setter accessors do not agree in visibility.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(21,9): error TS2379: Getter and setter accessors do not agree in visibility.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(27,26): error TS2379: Getter and setter accessors do not agree in visibility.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts(29,16): error TS2379: Getter and setter accessors do not agree in visibility.
==== tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithMismatchedAccessibilityModifiers.ts (8 errors) ====
class C {
get x() {
~
!!! error TS2379: Getter and setter accessors do not agree in visibility.
return 1;
}
private set x(v) {
~
!!! error TS2379: Getter and setter accessors do not agree in visibility.
}
}
class D {
protected get x() {
~
!!! error TS2379: Getter and setter accessors do not agree in visibility.
return 1;
}
private set x(v) {
~
!!! error TS2379: Getter and setter accessors do not agree in visibility.
}
}
class E {
protected set x(v) {
~
!!! error TS2379: Getter and setter accessors do not agree in visibility.
}
get x() {
~
!!! error TS2379: Getter and setter accessors do not agree in visibility.
return 1;
}
}
class F {
protected static set x(v) {
~
!!! error TS2379: Getter and setter accessors do not agree in visibility.
}
static get x() {
~
!!! error TS2379: Getter and setter accessors do not agree in visibility.
return 1;
}
}
@@ -0,0 +1,91 @@
//// [accessorWithMismatchedAccessibilityModifiers.ts]
class C {
get x() {
return 1;
}
private set x(v) {
}
}
class D {
protected get x() {
return 1;
}
private set x(v) {
}
}
class E {
protected set x(v) {
}
get x() {
return 1;
}
}
class F {
protected static set x(v) {
}
static get x() {
return 1;
}
}
//// [accessorWithMismatchedAccessibilityModifiers.js]
var C = (function () {
function C() {
}
Object.defineProperty(C.prototype, "x", {
get: function () {
return 1;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
return C;
})();
var D = (function () {
function D() {
}
Object.defineProperty(D.prototype, "x", {
get: function () {
return 1;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
return D;
})();
var E = (function () {
function E() {
}
Object.defineProperty(E.prototype, "x", {
get: function () {
return 1;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
return E;
})();
var F = (function () {
function F() {
}
Object.defineProperty(F, "x", {
get: function () {
return 1;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
return F;
})();
@@ -0,0 +1,35 @@
tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersAccessibility.ts(12,1): error TS2341: Property 'p' is private and only accessible within class 'C2'.
tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersAccessibility.ts(19,1): error TS2445: Property 'p' is protected and only accessible within class 'C3' and its subclasses.
==== tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersAccessibility.ts (2 errors) ====
class C1 {
constructor(public x: number) { }
}
var c1: C1;
c1.x // OK
class C2 {
constructor(private p: number) { }
}
var c2: C2;
c2.p // private, error
~~~~
!!! error TS2341: Property 'p' is private and only accessible within class 'C2'.
class C3 {
constructor(protected p: number) { }
}
var c3: C3;
c3.p // protected, error
~~~~
!!! error TS2445: Property 'p' is protected and only accessible within class 'C3' and its subclasses.
class Derived extends C3 {
constructor(p: number) {
super(p);
this.p; // OK
}
}
@@ -0,0 +1,67 @@
//// [classConstructorParametersAccessibility.ts]
class C1 {
constructor(public x: number) { }
}
var c1: C1;
c1.x // OK
class C2 {
constructor(private p: number) { }
}
var c2: C2;
c2.p // private, error
class C3 {
constructor(protected p: number) { }
}
var c3: C3;
c3.p // protected, error
class Derived extends C3 {
constructor(p: number) {
super(p);
this.p; // OK
}
}
//// [classConstructorParametersAccessibility.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var C1 = (function () {
function C1(x) {
this.x = x;
}
return C1;
})();
var c1;
c1.x; // OK
var C2 = (function () {
function C2(p) {
this.p = p;
}
return C2;
})();
var c2;
c2.p; // private, error
var C3 = (function () {
function C3(p) {
this.p = p;
}
return C3;
})();
var c3;
c3.p; // protected, error
var Derived = (function (_super) {
__extends(Derived, _super);
function Derived(p) {
_super.call(this, p);
this.p; // OK
}
return Derived;
})(C3);
@@ -0,0 +1,35 @@
tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersAccessibility2.ts(12,1): error TS2341: Property 'p' is private and only accessible within class 'C2'.
tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersAccessibility2.ts(19,1): error TS2445: Property 'p' is protected and only accessible within class 'C3' and its subclasses.
==== tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersAccessibility2.ts (2 errors) ====
class C1 {
constructor(public x?: number) { }
}
var c1: C1;
c1.x // OK
class C2 {
constructor(private p?: number) { }
}
var c2: C2;
c2.p // private, error
~~~~
!!! error TS2341: Property 'p' is private and only accessible within class 'C2'.
class C3 {
constructor(protected p?: number) { }
}
var c3: C3;
c3.p // protected, error
~~~~
!!! error TS2445: Property 'p' is protected and only accessible within class 'C3' and its subclasses.
class Derived extends C3 {
constructor(p: number) {
super(p);
this.p; // OK
}
}
@@ -0,0 +1,67 @@
//// [classConstructorParametersAccessibility2.ts]
class C1 {
constructor(public x?: number) { }
}
var c1: C1;
c1.x // OK
class C2 {
constructor(private p?: number) { }
}
var c2: C2;
c2.p // private, error
class C3 {
constructor(protected p?: number) { }
}
var c3: C3;
c3.p // protected, error
class Derived extends C3 {
constructor(p: number) {
super(p);
this.p; // OK
}
}
//// [classConstructorParametersAccessibility2.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var C1 = (function () {
function C1(x) {
this.x = x;
}
return C1;
})();
var c1;
c1.x; // OK
var C2 = (function () {
function C2(p) {
this.p = p;
}
return C2;
})();
var c2;
c2.p; // private, error
var C3 = (function () {
function C3(p) {
this.p = p;
}
return C3;
})();
var c3;
c3.p; // protected, error
var Derived = (function (_super) {
__extends(Derived, _super);
function Derived(p) {
_super.call(this, p);
this.p; // OK
}
return Derived;
})(C3);
@@ -0,0 +1,39 @@
//// [classConstructorParametersAccessibility3.ts]
class Base {
constructor(protected p: number) { }
}
class Derived extends Base {
constructor(public p: number) {
super(p);
this.p; // OK
}
}
var d: Derived;
d.p; // public, OK
//// [classConstructorParametersAccessibility3.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Base = (function () {
function Base(p) {
this.p = p;
}
return Base;
})();
var Derived = (function (_super) {
__extends(Derived, _super);
function Derived(p) {
_super.call(this, p);
this.p = p;
this.p; // OK
}
return Derived;
})(Base);
var d;
d.p; // public, OK
@@ -0,0 +1,36 @@
=== tests/cases/conformance/classes/constructorDeclarations/classConstructorParametersAccessibility3.ts ===
class Base {
>Base : Base
constructor(protected p: number) { }
>p : number
}
class Derived extends Base {
>Derived : Derived
>Base : Base
constructor(public p: number) {
>p : number
super(p);
>super(p) : void
>super : typeof Base
>p : number
this.p; // OK
>this.p : number
>this : Derived
>p : number
}
}
var d: Derived;
>d : Derived
>Derived : Derived
d.p; // public, OK
>d.p : number
>d : Derived
>p : number
@@ -0,0 +1,71 @@
//// [classWithProtectedProperty.ts]
// accessing any private outside the class is an error
class C {
protected x;
protected a = '';
protected b: string = '';
protected c() { return '' }
protected d = () => '';
protected static e;
protected static f() { return '' }
protected static g = () => '';
}
class D extends C {
method() {
// No errors
var d = new D();
var r1: string = d.x;
var r2: string = d.a;
var r3: string = d.b;
var r4: string = d.c();
var r5: string = d.d();
var r6: string = C.e;
var r7: string = C.f();
var r8: string = C.g();
}
}
//// [classWithProtectedProperty.js]
// accessing any private outside the class is an error
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var C = (function () {
function C() {
this.a = '';
this.b = '';
this.d = function () { return ''; };
}
C.prototype.c = function () {
return '';
};
C.f = function () {
return '';
};
C.g = function () { return ''; };
return C;
})();
var D = (function (_super) {
__extends(D, _super);
function D() {
_super.apply(this, arguments);
}
D.prototype.method = function () {
// No errors
var d = new D();
var r1 = d.x;
var r2 = d.a;
var r3 = d.b;
var r4 = d.c();
var r5 = d.d();
var r6 = C.e;
var r7 = C.f();
var r8 = C.g();
};
return D;
})(C);
@@ -0,0 +1,99 @@
=== tests/cases/conformance/types/members/classWithProtectedProperty.ts ===
// accessing any private outside the class is an error
class C {
>C : C
protected x;
>x : any
protected a = '';
>a : string
protected b: string = '';
>b : string
protected c() { return '' }
>c : () => string
protected d = () => '';
>d : () => string
>() => '' : () => string
protected static e;
>e : any
protected static f() { return '' }
>f : () => string
protected static g = () => '';
>g : () => string
>() => '' : () => string
}
class D extends C {
>D : D
>C : C
method() {
>method : () => void
// No errors
var d = new D();
>d : D
>new D() : D
>D : typeof D
var r1: string = d.x;
>r1 : string
>d.x : any
>d : D
>x : any
var r2: string = d.a;
>r2 : string
>d.a : string
>d : D
>a : string
var r3: string = d.b;
>r3 : string
>d.b : string
>d : D
>b : string
var r4: string = d.c();
>r4 : string
>d.c() : string
>d.c : () => string
>d : D
>c : () => string
var r5: string = d.d();
>r5 : string
>d.d() : string
>d.d : () => string
>d : D
>d : () => string
var r6: string = C.e;
>r6 : string
>C.e : any
>C : typeof C
>e : any
var r7: string = C.f();
>r7 : string
>C.f() : string
>C.f : () => string
>C : typeof C
>f : () => string
var r8: string = C.g();
>r8 : string
>C.g() : string
>C.g : () => string
>C : typeof C
>g : () => string
}
}
@@ -0,0 +1,164 @@
//// [declarationEmit_protectedMembers.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) { }
}
//// [declarationEmit_protectedMembers.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
// Class with protected members
var C1 = (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 = (function (_super) {
__extends(C2, _super);
function C2() {
_super.apply(this, arguments);
}
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 = (function (_super) {
__extends(C3, _super);
function C3() {
_super.apply(this, arguments);
}
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 = (function () {
function C4(a, b) {
this.a = a;
this.b = b;
}
return C4;
})();
//// [declarationEmit_protectedMembers.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 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 staticGetter: number;
}
declare class C4 {
protected a: number;
protected b: any;
constructor(a: number, b: any);
}
@@ -0,0 +1,120 @@
=== tests/cases/compiler/declarationEmit_protectedMembers.ts ===
// Class with protected members
class C1 {
>C1 : C1
protected x: number;
>x : number
protected f() {
>f : () => number
return this.x;
>this.x : number
>this : C1
>x : number
}
protected set accessor(a: number) { }
>accessor : number
>a : number
protected get accessor() { return 0; }
>accessor : number
protected static sx: number;
>sx : number
protected static sf() {
>sf : () => number
return this.sx;
>this.sx : number
>this : typeof C1
>sx : number
}
protected static set staticSetter(a: number) { }
>staticSetter : number
>a : number
protected static get staticGetter() { return 0; }
>staticGetter : number
}
// Derived class overriding protected members
class C2 extends C1 {
>C2 : C2
>C1 : C1
protected f() {
>f : () => number
return super.f() + this.x;
>super.f() + this.x : number
>super.f() : number
>super.f : () => number
>super : C1
>f : () => number
>this.x : number
>this : C2
>x : number
}
protected static sf() {
>sf : () => number
return super.sf() + this.sx;
>super.sf() + this.sx : number
>super.sf() : number
>super.sf : () => number
>super : typeof C1
>sf : () => number
>this.sx : number
>this : typeof C2
>sx : number
}
}
// Derived class making protected members public
class C3 extends C2 {
>C3 : C3
>C2 : C2
x: number;
>x : number
static sx: number;
>sx : number
f() {
>f : () => number
return super.f();
>super.f() : number
>super.f : () => number
>super : C2
>f : () => number
}
static sf() {
>sf : () => number
return super.sf();
>super.sf() : number
>super.sf : () => number
>super : typeof C2
>sf : () => number
}
static get staticGetter() { return 1; }
>staticGetter : number
}
// Protected properties in constructors
class C4 {
>C4 : C4
constructor(protected a: number, protected b) { }
>a : number
>b : any
}
@@ -0,0 +1,103 @@
//// [derivedClassOverridesProtectedMembers.ts]
var x: { foo: string; }
var y: { foo: string; bar: string; }
class Base {
protected a: typeof x;
protected b(a: typeof x) { }
protected get c() { return x; }
protected set c(v: typeof x) { }
protected d: (a: typeof x) => void;
protected static r: typeof x;
protected static s(a: typeof x) { }
protected static get t() { return x; }
protected static set t(v: typeof x) { }
protected static u: (a: typeof x) => void;
constructor(a: typeof x) { }
}
class Derived extends Base {
protected a: typeof y;
protected b(a: typeof y) { }
protected get c() { return y; }
protected set c(v: typeof y) { }
protected d: (a: typeof y) => void;
protected static r: typeof y;
protected static s(a: typeof y) { }
protected static get t() { return y; }
protected static set t(a: typeof y) { }
protected static u: (a: typeof y) => void;
constructor(a: typeof y) { super(x) }
}
//// [derivedClassOverridesProtectedMembers.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var x;
var y;
var Base = (function () {
function Base(a) {
}
Base.prototype.b = function (a) {
};
Object.defineProperty(Base.prototype, "c", {
get: function () {
return x;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
Base.s = function (a) {
};
Object.defineProperty(Base, "t", {
get: function () {
return x;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
return Base;
})();
var Derived = (function (_super) {
__extends(Derived, _super);
function Derived(a) {
_super.call(this, x);
}
Derived.prototype.b = function (a) {
};
Object.defineProperty(Derived.prototype, "c", {
get: function () {
return y;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
Derived.s = function (a) {
};
Object.defineProperty(Derived, "t", {
get: function () {
return y;
},
set: function (a) {
},
enumerable: true,
configurable: true
});
return Derived;
})(Base);
@@ -0,0 +1,123 @@
=== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers.ts ===
var x: { foo: string; }
>x : { foo: string; }
>foo : string
var y: { foo: string; bar: string; }
>y : { foo: string; bar: string; }
>foo : string
>bar : string
class Base {
>Base : Base
protected a: typeof x;
>a : { foo: string; }
>x : { foo: string; }
protected b(a: typeof x) { }
>b : (a: { foo: string; }) => void
>a : { foo: string; }
>x : { foo: string; }
protected get c() { return x; }
>c : { foo: string; }
>x : { foo: string; }
protected set c(v: typeof x) { }
>c : { foo: string; }
>v : { foo: string; }
>x : { foo: string; }
protected d: (a: typeof x) => void;
>d : (a: { foo: string; }) => void
>a : { foo: string; }
>x : { foo: string; }
protected static r: typeof x;
>r : { foo: string; }
>x : { foo: string; }
protected static s(a: typeof x) { }
>s : (a: { foo: string; }) => void
>a : { foo: string; }
>x : { foo: string; }
protected static get t() { return x; }
>t : { foo: string; }
>x : { foo: string; }
protected static set t(v: typeof x) { }
>t : { foo: string; }
>v : { foo: string; }
>x : { foo: string; }
protected static u: (a: typeof x) => void;
>u : (a: { foo: string; }) => void
>a : { foo: string; }
>x : { foo: string; }
constructor(a: typeof x) { }
>a : { foo: string; }
>x : { foo: string; }
}
class Derived extends Base {
>Derived : Derived
>Base : Base
protected a: typeof y;
>a : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
protected b(a: typeof y) { }
>b : (a: { foo: string; bar: string; }) => void
>a : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
protected get c() { return y; }
>c : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
protected set c(v: typeof y) { }
>c : { foo: string; bar: string; }
>v : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
protected d: (a: typeof y) => void;
>d : (a: { foo: string; bar: string; }) => void
>a : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
protected static r: typeof y;
>r : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
protected static s(a: typeof y) { }
>s : (a: { foo: string; bar: string; }) => void
>a : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
protected static get t() { return y; }
>t : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
protected static set t(a: typeof y) { }
>t : { foo: string; bar: string; }
>a : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
protected static u: (a: typeof y) => void;
>u : (a: { foo: string; bar: string; }) => void
>a : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
constructor(a: typeof y) { super(x) }
>a : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
>super(x) : void
>super : typeof Base
>x : { foo: string; }
}
@@ -0,0 +1,157 @@
//// [derivedClassOverridesProtectedMembers2.ts]
var x: { foo: string; }
var y: { foo: string; bar: string; }
class Base {
protected a: typeof x;
protected b(a: typeof x) { }
protected get c() { return x; }
protected set c(v: typeof x) { }
protected d: (a: typeof x) => void ;
protected static r: typeof x;
protected static s(a: typeof x) { }
protected static get t() { return x; }
protected static set t(v: typeof x) { }
protected static u: (a: typeof x) => void ;
constructor(a: typeof x) { }
}
// Increase visibility of all protected members to public
class Derived extends Base {
a: typeof y;
b(a: typeof y) { }
get c() { return y; }
set c(v: typeof y) { }
d: (a: typeof y) => void;
static r: typeof y;
static s(a: typeof y) { }
static get t() { return y; }
static set t(a: typeof y) { }
static u: (a: typeof y) => void;
constructor(a: typeof y) { super(a); }
}
var d: Derived = new Derived(y);
var r1 = d.a;
var r2 = d.b(y);
var r3 = d.c;
var r3a = d.d;
d.c = y;
var r4 = Derived.r;
var r5 = Derived.s(y);
var r6 = Derived.t;
var r6a = Derived.u;
Derived.t = y;
class Base2 {
[i: string]: Object;
[i: number]: typeof x;
}
class Derived2 extends Base2 {
[i: string]: typeof x;
[i: number]: typeof y;
}
var d2: Derived2;
var r7 = d2[''];
var r8 = d2[1];
//// [derivedClassOverridesProtectedMembers2.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var x;
var y;
var Base = (function () {
function Base(a) {
}
Base.prototype.b = function (a) {
};
Object.defineProperty(Base.prototype, "c", {
get: function () {
return x;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
Base.s = function (a) {
};
Object.defineProperty(Base, "t", {
get: function () {
return x;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
return Base;
})();
// Increase visibility of all protected members to public
var Derived = (function (_super) {
__extends(Derived, _super);
function Derived(a) {
_super.call(this, a);
}
Derived.prototype.b = function (a) {
};
Object.defineProperty(Derived.prototype, "c", {
get: function () {
return y;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
Derived.s = function (a) {
};
Object.defineProperty(Derived, "t", {
get: function () {
return y;
},
set: function (a) {
},
enumerable: true,
configurable: true
});
return Derived;
})(Base);
var d = new Derived(y);
var r1 = d.a;
var r2 = d.b(y);
var r3 = d.c;
var r3a = d.d;
d.c = y;
var r4 = Derived.r;
var r5 = Derived.s(y);
var r6 = Derived.t;
var r6a = Derived.u;
Derived.t = y;
var Base2 = (function () {
function Base2() {
}
return Base2;
})();
var Derived2 = (function (_super) {
__extends(Derived2, _super);
function Derived2() {
_super.apply(this, arguments);
}
return Derived2;
})(Base2);
var d2;
var r7 = d2[''];
var r8 = d2[1];
@@ -0,0 +1,236 @@
=== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers2.ts ===
var x: { foo: string; }
>x : { foo: string; }
>foo : string
var y: { foo: string; bar: string; }
>y : { foo: string; bar: string; }
>foo : string
>bar : string
class Base {
>Base : Base
protected a: typeof x;
>a : { foo: string; }
>x : { foo: string; }
protected b(a: typeof x) { }
>b : (a: { foo: string; }) => void
>a : { foo: string; }
>x : { foo: string; }
protected get c() { return x; }
>c : { foo: string; }
>x : { foo: string; }
protected set c(v: typeof x) { }
>c : { foo: string; }
>v : { foo: string; }
>x : { foo: string; }
protected d: (a: typeof x) => void ;
>d : (a: { foo: string; }) => void
>a : { foo: string; }
>x : { foo: string; }
protected static r: typeof x;
>r : { foo: string; }
>x : { foo: string; }
protected static s(a: typeof x) { }
>s : (a: { foo: string; }) => void
>a : { foo: string; }
>x : { foo: string; }
protected static get t() { return x; }
>t : { foo: string; }
>x : { foo: string; }
protected static set t(v: typeof x) { }
>t : { foo: string; }
>v : { foo: string; }
>x : { foo: string; }
protected static u: (a: typeof x) => void ;
>u : (a: { foo: string; }) => void
>a : { foo: string; }
>x : { foo: string; }
constructor(a: typeof x) { }
>a : { foo: string; }
>x : { foo: string; }
}
// Increase visibility of all protected members to public
class Derived extends Base {
>Derived : Derived
>Base : Base
a: typeof y;
>a : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
b(a: typeof y) { }
>b : (a: { foo: string; bar: string; }) => void
>a : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
get c() { return y; }
>c : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
set c(v: typeof y) { }
>c : { foo: string; bar: string; }
>v : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
d: (a: typeof y) => void;
>d : (a: { foo: string; bar: string; }) => void
>a : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
static r: typeof y;
>r : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
static s(a: typeof y) { }
>s : (a: { foo: string; bar: string; }) => void
>a : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
static get t() { return y; }
>t : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
static set t(a: typeof y) { }
>t : { foo: string; bar: string; }
>a : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
static u: (a: typeof y) => void;
>u : (a: { foo: string; bar: string; }) => void
>a : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
constructor(a: typeof y) { super(a); }
>a : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
>super(a) : void
>super : typeof Base
>a : { foo: string; bar: string; }
}
var d: Derived = new Derived(y);
>d : Derived
>Derived : Derived
>new Derived(y) : Derived
>Derived : typeof Derived
>y : { foo: string; bar: string; }
var r1 = d.a;
>r1 : { foo: string; bar: string; }
>d.a : { foo: string; bar: string; }
>d : Derived
>a : { foo: string; bar: string; }
var r2 = d.b(y);
>r2 : void
>d.b(y) : void
>d.b : (a: { foo: string; bar: string; }) => void
>d : Derived
>b : (a: { foo: string; bar: string; }) => void
>y : { foo: string; bar: string; }
var r3 = d.c;
>r3 : { foo: string; bar: string; }
>d.c : { foo: string; bar: string; }
>d : Derived
>c : { foo: string; bar: string; }
var r3a = d.d;
>r3a : (a: { foo: string; bar: string; }) => void
>d.d : (a: { foo: string; bar: string; }) => void
>d : Derived
>d : (a: { foo: string; bar: string; }) => void
d.c = y;
>d.c = y : { foo: string; bar: string; }
>d.c : { foo: string; bar: string; }
>d : Derived
>c : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
var r4 = Derived.r;
>r4 : { foo: string; bar: string; }
>Derived.r : { foo: string; bar: string; }
>Derived : typeof Derived
>r : { foo: string; bar: string; }
var r5 = Derived.s(y);
>r5 : void
>Derived.s(y) : void
>Derived.s : (a: { foo: string; bar: string; }) => void
>Derived : typeof Derived
>s : (a: { foo: string; bar: string; }) => void
>y : { foo: string; bar: string; }
var r6 = Derived.t;
>r6 : { foo: string; bar: string; }
>Derived.t : { foo: string; bar: string; }
>Derived : typeof Derived
>t : { foo: string; bar: string; }
var r6a = Derived.u;
>r6a : (a: { foo: string; bar: string; }) => void
>Derived.u : (a: { foo: string; bar: string; }) => void
>Derived : typeof Derived
>u : (a: { foo: string; bar: string; }) => void
Derived.t = y;
>Derived.t = y : { foo: string; bar: string; }
>Derived.t : { foo: string; bar: string; }
>Derived : typeof Derived
>t : { foo: string; bar: string; }
>y : { foo: string; bar: string; }
class Base2 {
>Base2 : Base2
[i: string]: Object;
>i : string
>Object : Object
[i: number]: typeof x;
>i : number
>x : { foo: string; }
}
class Derived2 extends Base2 {
>Derived2 : Derived2
>Base2 : Base2
[i: string]: typeof x;
>i : string
>x : { foo: string; }
[i: number]: typeof y;
>i : number
>y : { foo: string; bar: string; }
}
var d2: Derived2;
>d2 : Derived2
>Derived2 : Derived2
var r7 = d2[''];
>r7 : { foo: string; }
>d2[''] : { foo: string; }
>d2 : Derived2
var r8 = d2[1];
>r8 : { foo: string; bar: string; }
>d2[1] : { foo: string; bar: string; }
>d2 : Derived2
@@ -0,0 +1,124 @@
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(23,7): error TS2416: Class 'Derived1' incorrectly extends base class 'Base':
Property 'a' is protected in type 'Derived1' but public in type 'Base'.
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(28,7): error TS2416: Class 'Derived2' incorrectly extends base class 'Base':
Property 'b' is protected in type 'Derived2' but public in type 'Base'.
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(33,7): error TS2416: Class 'Derived3' incorrectly extends base class 'Base':
Property 'c' is protected in type 'Derived3' but public in type 'Base'.
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(38,7): error TS2416: Class 'Derived4' incorrectly extends base class 'Base':
Property 'c' is protected in type 'Derived4' but public in type 'Base'.
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(43,7): error TS2416: Class 'Derived5' incorrectly extends base class 'Base':
Property 'd' is protected in type 'Derived5' but public in type 'Base'.
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(48,7): error TS2418: Class static side 'typeof Derived6' incorrectly extends base class static side 'typeof Base':
Property 'r' is protected in type 'typeof Derived6' but public in type 'typeof Base'.
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(53,7): error TS2418: Class static side 'typeof Derived7' incorrectly extends base class static side 'typeof Base':
Property 's' is protected in type 'typeof Derived7' but public in type 'typeof Base'.
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(58,7): error TS2418: Class static side 'typeof Derived8' incorrectly extends base class static side 'typeof Base':
Property 't' is protected in type 'typeof Derived8' but public in type 'typeof Base'.
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(63,7): error TS2418: Class static side 'typeof Derived9' incorrectly extends base class static side 'typeof Base':
Property 't' is protected in type 'typeof Derived9' but public in type 'typeof Base'.
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts(68,7): error TS2418: Class static side 'typeof Derived10' incorrectly extends base class static side 'typeof Base':
Property 'u' is protected in type 'typeof Derived10' but public in type 'typeof Base'.
==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers3.ts (10 errors) ====
var x: { foo: string; }
var y: { foo: string; bar: string; }
class Base {
a: typeof x;
b(a: typeof x) { }
get c() { return x; }
set c(v: typeof x) { }
d: (a: typeof x) => void;
static r: typeof x;
static s(a: typeof x) { }
static get t() { return x; }
static set t(v: typeof x) { }
static u: (a: typeof x) => void;
constructor(a: typeof x) {}
}
// Errors
// decrease visibility of all public members to protected
class Derived1 extends Base {
~~~~~~~~
!!! error TS2416: Class 'Derived1' incorrectly extends base class 'Base':
!!! error TS2416: Property 'a' is protected in type 'Derived1' but public in type 'Base'.
protected a: typeof x;
constructor(a: typeof x) { super(a); }
}
class Derived2 extends Base {
~~~~~~~~
!!! error TS2416: Class 'Derived2' incorrectly extends base class 'Base':
!!! error TS2416: Property 'b' is protected in type 'Derived2' but public in type 'Base'.
protected b(a: typeof x) { }
constructor(a: typeof x) { super(a); }
}
class Derived3 extends Base {
~~~~~~~~
!!! error TS2416: Class 'Derived3' incorrectly extends base class 'Base':
!!! error TS2416: Property 'c' is protected in type 'Derived3' but public in type 'Base'.
protected get c() { return x; }
constructor(a: typeof x) { super(a); }
}
class Derived4 extends Base {
~~~~~~~~
!!! error TS2416: Class 'Derived4' incorrectly extends base class 'Base':
!!! error TS2416: Property 'c' is protected in type 'Derived4' but public in type 'Base'.
protected set c(v: typeof x) { }
constructor(a: typeof x) { super(a); }
}
class Derived5 extends Base {
~~~~~~~~
!!! error TS2416: Class 'Derived5' incorrectly extends base class 'Base':
!!! error TS2416: Property 'd' is protected in type 'Derived5' but public in type 'Base'.
protected d: (a: typeof x) => void ;
constructor(a: typeof x) { super(a); }
}
class Derived6 extends Base {
~~~~~~~~
!!! error TS2418: Class static side 'typeof Derived6' incorrectly extends base class static side 'typeof Base':
!!! error TS2418: Property 'r' is protected in type 'typeof Derived6' but public in type 'typeof Base'.
protected static r: typeof x;
constructor(a: typeof x) { super(a); }
}
class Derived7 extends Base {
~~~~~~~~
!!! error TS2418: Class static side 'typeof Derived7' incorrectly extends base class static side 'typeof Base':
!!! error TS2418: Property 's' is protected in type 'typeof Derived7' but public in type 'typeof Base'.
protected static s(a: typeof x) { }
constructor(a: typeof x) { super(a); }
}
class Derived8 extends Base {
~~~~~~~~
!!! error TS2418: Class static side 'typeof Derived8' incorrectly extends base class static side 'typeof Base':
!!! error TS2418: Property 't' is protected in type 'typeof Derived8' but public in type 'typeof Base'.
protected static get t() { return x; }
constructor(a: typeof x) { super(a); }
}
class Derived9 extends Base {
~~~~~~~~
!!! error TS2418: Class static side 'typeof Derived9' incorrectly extends base class static side 'typeof Base':
!!! error TS2418: Property 't' is protected in type 'typeof Derived9' but public in type 'typeof Base'.
protected static set t(v: typeof x) { }
constructor(a: typeof x) { super(a); }
}
class Derived10 extends Base {
~~~~~~~~~
!!! error TS2418: Class static side 'typeof Derived10' incorrectly extends base class static side 'typeof Base':
!!! error TS2418: Property 'u' is protected in type 'typeof Derived10' but public in type 'typeof Base'.
protected static u: (a: typeof x) => void ;
constructor(a: typeof x) { super(a); }
}
@@ -0,0 +1,211 @@
//// [derivedClassOverridesProtectedMembers3.ts]
var x: { foo: string; }
var y: { foo: string; bar: string; }
class Base {
a: typeof x;
b(a: typeof x) { }
get c() { return x; }
set c(v: typeof x) { }
d: (a: typeof x) => void;
static r: typeof x;
static s(a: typeof x) { }
static get t() { return x; }
static set t(v: typeof x) { }
static u: (a: typeof x) => void;
constructor(a: typeof x) {}
}
// Errors
// decrease visibility of all public members to protected
class Derived1 extends Base {
protected a: typeof x;
constructor(a: typeof x) { super(a); }
}
class Derived2 extends Base {
protected b(a: typeof x) { }
constructor(a: typeof x) { super(a); }
}
class Derived3 extends Base {
protected get c() { return x; }
constructor(a: typeof x) { super(a); }
}
class Derived4 extends Base {
protected set c(v: typeof x) { }
constructor(a: typeof x) { super(a); }
}
class Derived5 extends Base {
protected d: (a: typeof x) => void ;
constructor(a: typeof x) { super(a); }
}
class Derived6 extends Base {
protected static r: typeof x;
constructor(a: typeof x) { super(a); }
}
class Derived7 extends Base {
protected static s(a: typeof x) { }
constructor(a: typeof x) { super(a); }
}
class Derived8 extends Base {
protected static get t() { return x; }
constructor(a: typeof x) { super(a); }
}
class Derived9 extends Base {
protected static set t(v: typeof x) { }
constructor(a: typeof x) { super(a); }
}
class Derived10 extends Base {
protected static u: (a: typeof x) => void ;
constructor(a: typeof x) { super(a); }
}
//// [derivedClassOverridesProtectedMembers3.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var x;
var y;
var Base = (function () {
function Base(a) {
}
Base.prototype.b = function (a) {
};
Object.defineProperty(Base.prototype, "c", {
get: function () {
return x;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
Base.s = function (a) {
};
Object.defineProperty(Base, "t", {
get: function () {
return x;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
return Base;
})();
// Errors
// decrease visibility of all public members to protected
var Derived1 = (function (_super) {
__extends(Derived1, _super);
function Derived1(a) {
_super.call(this, a);
}
return Derived1;
})(Base);
var Derived2 = (function (_super) {
__extends(Derived2, _super);
function Derived2(a) {
_super.call(this, a);
}
Derived2.prototype.b = function (a) {
};
return Derived2;
})(Base);
var Derived3 = (function (_super) {
__extends(Derived3, _super);
function Derived3(a) {
_super.call(this, a);
}
Object.defineProperty(Derived3.prototype, "c", {
get: function () {
return x;
},
enumerable: true,
configurable: true
});
return Derived3;
})(Base);
var Derived4 = (function (_super) {
__extends(Derived4, _super);
function Derived4(a) {
_super.call(this, a);
}
Object.defineProperty(Derived4.prototype, "c", {
set: function (v) {
},
enumerable: true,
configurable: true
});
return Derived4;
})(Base);
var Derived5 = (function (_super) {
__extends(Derived5, _super);
function Derived5(a) {
_super.call(this, a);
}
return Derived5;
})(Base);
var Derived6 = (function (_super) {
__extends(Derived6, _super);
function Derived6(a) {
_super.call(this, a);
}
return Derived6;
})(Base);
var Derived7 = (function (_super) {
__extends(Derived7, _super);
function Derived7(a) {
_super.call(this, a);
}
Derived7.s = function (a) {
};
return Derived7;
})(Base);
var Derived8 = (function (_super) {
__extends(Derived8, _super);
function Derived8(a) {
_super.call(this, a);
}
Object.defineProperty(Derived8, "t", {
get: function () {
return x;
},
enumerable: true,
configurable: true
});
return Derived8;
})(Base);
var Derived9 = (function (_super) {
__extends(Derived9, _super);
function Derived9(a) {
_super.call(this, a);
}
Object.defineProperty(Derived9, "t", {
set: function (v) {
},
enumerable: true,
configurable: true
});
return Derived9;
})(Base);
var Derived10 = (function (_super) {
__extends(Derived10, _super);
function Derived10(a) {
_super.call(this, a);
}
return Derived10;
})(Base);
@@ -0,0 +1,22 @@
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts(12,7): error TS2416: Class 'Derived2' incorrectly extends base class 'Derived1':
Property 'a' is protected in type 'Derived2' but public in type 'Derived1'.
==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassOverridesProtectedMembers4.ts (1 errors) ====
var x: { foo: string; }
var y: { foo: string; bar: string; }
class Base {
protected a: typeof x;
}
class Derived1 extends Base {
public a: typeof x;
}
class Derived2 extends Derived1 {
~~~~~~~~
!!! error TS2416: Class 'Derived2' incorrectly extends base class 'Derived1':
!!! error TS2416: Property 'a' is protected in type 'Derived2' but public in type 'Derived1'.
protected a: typeof x; // Error, parent was public
}
@@ -0,0 +1,44 @@
//// [derivedClassOverridesProtectedMembers4.ts]
var x: { foo: string; }
var y: { foo: string; bar: string; }
class Base {
protected a: typeof x;
}
class Derived1 extends Base {
public a: typeof x;
}
class Derived2 extends Derived1 {
protected a: typeof x; // Error, parent was public
}
//// [derivedClassOverridesProtectedMembers4.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var x;
var y;
var Base = (function () {
function Base() {
}
return Base;
})();
var Derived1 = (function (_super) {
__extends(Derived1, _super);
function Derived1() {
_super.apply(this, arguments);
}
return Derived1;
})(Base);
var Derived2 = (function (_super) {
__extends(Derived2, _super);
function Derived2() {
_super.apply(this, arguments);
}
return Derived2;
})(Derived1);
@@ -0,0 +1,37 @@
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassTransitivity4.ts(18,1): error TS2322: Type 'E' is not assignable to type 'C':
Types of property 'foo' are incompatible:
Type '(x?: string) => void' is not assignable to type '(x: number) => void':
Types of parameters 'x' and 'x' are incompatible:
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassTransitivity4.ts(19,9): error TS2445: Property 'foo' is protected and only accessible within class 'C' and its subclasses.
==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassTransitivity4.ts (2 errors) ====
// subclassing is not transitive when you can remove required parameters and add optional parameters on protected members
class C {
protected foo(x: number) { }
}
class D extends C {
protected foo() { } // ok to drop parameters
}
class E extends D {
public foo(x?: string) { } // ok to add optional parameters
}
var c: C;
var d: D;
var e: E;
c = e;
~
!!! error TS2322: Type 'E' is not assignable to type 'C':
!!! error TS2322: Types of property 'foo' are incompatible:
!!! error TS2322: Type '(x?: string) => void' is not assignable to type '(x: number) => void':
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible:
!!! error TS2322: Type 'string' is not assignable to type 'number'.
var r = c.foo(1);
~~~~~
!!! error TS2445: Property 'foo' is protected and only accessible within class 'C' and its subclasses.
var r2 = e.foo('');
@@ -0,0 +1,61 @@
//// [derivedClassTransitivity4.ts]
// subclassing is not transitive when you can remove required parameters and add optional parameters on protected members
class C {
protected foo(x: number) { }
}
class D extends C {
protected foo() { } // ok to drop parameters
}
class E extends D {
public foo(x?: string) { } // ok to add optional parameters
}
var c: C;
var d: D;
var e: E;
c = e;
var r = c.foo(1);
var r2 = e.foo('');
//// [derivedClassTransitivity4.js]
// subclassing is not transitive when you can remove required parameters and add optional parameters on protected members
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var C = (function () {
function C() {
}
C.prototype.foo = function (x) {
};
return C;
})();
var D = (function (_super) {
__extends(D, _super);
function D() {
_super.apply(this, arguments);
}
D.prototype.foo = function () {
}; // ok to drop parameters
return D;
})(C);
var E = (function (_super) {
__extends(E, _super);
function E() {
_super.apply(this, arguments);
}
E.prototype.foo = function (x) {
}; // ok to add optional parameters
return E;
})(D);
var c;
var d;
var e;
c = e;
var r = c.foo(1);
var r2 = e.foo('');
@@ -0,0 +1,30 @@
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingProtectedInstance.ts(13,7): error TS2416: Class 'Derived' incorrectly extends base class 'Base':
Property 'x' is private in type 'Derived' but not in type 'Base'.
==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateInstanceShadowingProtectedInstance.ts (1 errors) ====
class Base {
protected x: string;
protected fn(): string {
return '';
}
protected get a() { return 1; }
protected set a(v) { }
}
// error, not a subtype
class Derived extends Base {
~~~~~~~
!!! error TS2416: Class 'Derived' incorrectly extends base class 'Base':
!!! error TS2416: Property 'x' is private in type 'Derived' but not in type 'Base'.
private x: string;
private fn(): string {
return '';
}
private get a() { return 1; }
private set a(v) { }
}
@@ -0,0 +1,68 @@
//// [derivedClassWithPrivateInstanceShadowingProtectedInstance.ts]
class Base {
protected x: string;
protected fn(): string {
return '';
}
protected get a() { return 1; }
protected set a(v) { }
}
// error, not a subtype
class Derived extends Base {
private x: string;
private fn(): string {
return '';
}
private get a() { return 1; }
private set a(v) { }
}
//// [derivedClassWithPrivateInstanceShadowingProtectedInstance.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Base = (function () {
function Base() {
}
Base.prototype.fn = function () {
return '';
};
Object.defineProperty(Base.prototype, "a", {
get: function () {
return 1;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
return Base;
})();
// error, not a subtype
var Derived = (function (_super) {
__extends(Derived, _super);
function Derived() {
_super.apply(this, arguments);
}
Derived.prototype.fn = function () {
return '';
};
Object.defineProperty(Derived.prototype, "a", {
get: function () {
return 1;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
return Derived;
})(Base);
@@ -0,0 +1,29 @@
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingProtectedStatic.ts(13,7): error TS2418: Class static side 'typeof Derived' incorrectly extends base class static side 'typeof Base':
Property 'x' is private in type 'typeof Derived' but not in type 'typeof Base'.
==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingProtectedStatic.ts (1 errors) ====
class Base {
protected static x: string;
protected static fn(): string {
return '';
}
protected static get a() { return 1; }
protected static set a(v) { }
}
// should be error
class Derived extends Base {
~~~~~~~
!!! error TS2418: Class static side 'typeof Derived' incorrectly extends base class static side 'typeof Base':
!!! error TS2418: Property 'x' is private in type 'typeof Derived' but not in type 'typeof Base'.
private static x: string;
private static fn(): string {
return '';
}
private static get a() { return 1; }
private static set a(v) { }
}
@@ -0,0 +1,67 @@
//// [derivedClassWithPrivateStaticShadowingProtectedStatic.ts]
class Base {
protected static x: string;
protected static fn(): string {
return '';
}
protected static get a() { return 1; }
protected static set a(v) { }
}
// should be error
class Derived extends Base {
private static x: string;
private static fn(): string {
return '';
}
private static get a() { return 1; }
private static set a(v) { }
}
//// [derivedClassWithPrivateStaticShadowingProtectedStatic.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Base = (function () {
function Base() {
}
Base.fn = function () {
return '';
};
Object.defineProperty(Base, "a", {
get: function () {
return 1;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
return Base;
})();
// should be error
var Derived = (function (_super) {
__extends(Derived, _super);
function Derived() {
_super.apply(this, arguments);
}
Derived.fn = function () {
return '';
};
Object.defineProperty(Derived, "a", {
get: function () {
return 1;
},
set: function (v) {
},
enumerable: true,
configurable: true
});
return Derived;
})(Base);
@@ -0,0 +1,18 @@
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(3,5): error TS1131: Property or signature expected.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(4,5): error TS1131: Property or signature expected.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts(5,5): error TS1131: Property or signature expected.
==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithAccessibilityModifiers.ts (3 errors) ====
// Errors
interface Foo {
public a: any;
~~~~~~
!!! error TS1131: Property or signature expected.
private b: any;
~~~~~~~
!!! error TS1131: Property or signature expected.
protected c: any;
~~~~~~~~~
!!! error TS1131: Property or signature expected.
}
@@ -1,16 +1,21 @@
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(3,12): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(7,12): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(12,19): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(16,19): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(23,12): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(27,12): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(32,19): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(36,19): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(42,9): error TS2341: Property 'foo' is private and only accessible within class 'C'.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(45,10): error TS2341: Property 'foo' is private and only accessible within class 'D<T>'.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(15,15): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(16,15): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(20,19): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(25,19): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(32,12): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(36,12): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(41,15): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(45,19): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(49,19): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(53,19): error TS2385: Overload signatures must all be public, private or protected.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(59,9): error TS2341: Property 'foo' is private and only accessible within class 'C'.
tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(62,10): error TS2341: Property 'foo' is private and only accessible within class 'D<T>'.
==== tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts (10 errors) ====
==== tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts (15 errors) ====
class C {
private foo(x: number);
public foo(x: number, y: string); // error
@@ -31,12 +36,27 @@ tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclara
!!! error TS2385: Overload signatures must all be public, private or protected.
private static foo(x: any, y?: any) { }
protected baz(x: string); // error
~~~
!!! error TS2385: Overload signatures must all be public, private or protected.
protected baz(x: number, y: string); // error
~~~
!!! error TS2385: Overload signatures must all be public, private or protected.
private baz(x: any, y?: any) { }
private static bar(x: 'hi');
public static bar(x: string); // error
~~~
!!! error TS2385: Overload signatures must all be public, private or protected.
private static bar(x: number, y: string);
private static bar(x: any, y?: any) { }
protected static baz(x: 'hi');
public static baz(x: string); // error
~~~
!!! error TS2385: Overload signatures must all be public, private or protected.
protected static baz(x: number, y: string);
protected static baz(x: any, y?: any) { }
}
class D<T> {
@@ -53,6 +73,12 @@ tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclara
private bar(x: T, y: T);
private bar(x: any, y?: any) { }
private baz(x: string);
protected baz(x: number, y: string); // error
~~~
!!! error TS2385: Overload signatures must all be public, private or protected.
private baz(x: any, y?: any) { }
private static foo(x: number);
public static foo(x: number, y: string); // error
~~~
@@ -65,6 +91,12 @@ tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclara
!!! error TS2385: Overload signatures must all be public, private or protected.
private static bar(x: number, y: string);
private static bar(x: any, y?: any) { }
public static baz(x: string); // error
~~~
!!! error TS2385: Overload signatures must all be public, private or protected.
protected static baz(x: number, y: string);
protected static baz(x: any, y?: any) { }
}
var c: C;
@@ -13,10 +13,19 @@ class C {
public static foo(x: number, y: string); // error
private static foo(x: any, y?: any) { }
protected baz(x: string); // error
protected baz(x: number, y: string); // error
private baz(x: any, y?: any) { }
private static bar(x: 'hi');
public static bar(x: string); // error
private static bar(x: number, y: string);
private static bar(x: any, y?: any) { }
protected static baz(x: 'hi');
public static baz(x: string); // error
protected static baz(x: number, y: string);
protected static baz(x: any, y?: any) { }
}
class D<T> {
@@ -29,6 +38,10 @@ class D<T> {
private bar(x: T, y: T);
private bar(x: any, y?: any) { }
private baz(x: string);
protected baz(x: number, y: string); // error
private baz(x: any, y?: any) { }
private static foo(x: number);
public static foo(x: number, y: string); // error
private static foo(x: any, y?: any) { }
@@ -37,6 +50,10 @@ class D<T> {
public static bar(x: string); // error
private static bar(x: number, y: string);
private static bar(x: any, y?: any) { }
public static baz(x: string); // error
protected static baz(x: number, y: string);
protected static baz(x: any, y?: any) { }
}
var c: C;
@@ -55,8 +72,12 @@ var C = (function () {
};
C.foo = function (x, y) {
};
C.prototype.baz = function (x, y) {
};
C.bar = function (x, y) {
};
C.baz = function (x, y) {
};
return C;
})();
var D = (function () {
@@ -66,10 +87,14 @@ var D = (function () {
};
D.prototype.bar = function (x, y) {
};
D.prototype.baz = function (x, y) {
};
D.foo = function (x, y) {
};
D.bar = function (x, y) {
};
D.baz = function (x, y) {
};
return D;
})();
var c;
@@ -0,0 +1,160 @@
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(13,9): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(26,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(28,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(29,9): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(30,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(42,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(43,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(45,9): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(59,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(60,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(61,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(63,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(75,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(76,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(77,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(78,9): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(90,1): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(91,1): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(92,1): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(93,1): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts(94,1): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
==== tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass2.ts (21 errors) ====
class Base {
protected x: string;
method() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // OK, accessed within their declaring class
d1.x; // OK, accessed within their declaring class
d2.x; // OK, accessed within their declaring class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
d4.x; // OK, accessed within their declaring class
}
}
class Derived1 extends Base {
method1() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, isn't accessed through an instance of the enclosing class
~~~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'.
d1.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
d2.x; // Error, isn't accessed through an instance of the enclosing class
~~~~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'.
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
d4.x; // Error, isn't accessed through an instance of the enclosing class
~~~~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived1'.
}
}
class Derived2 extends Base {
method2() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, isn't accessed through an instance of the enclosing class
~~~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'.
d1.x; // Error, isn't accessed through an instance of the enclosing class
~~~~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived2'.
d2.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
d4.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class or one of its subclasses
}
}
class Derived3 extends Derived1 {
protected x: string;
method3() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, isn't accessed through an instance of the enclosing class
~~~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
d1.x; // Error, isn't accessed through an instance of the enclosing class
~~~~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
d2.x; // Error, isn't accessed through an instance of the enclosing class
~~~~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
d3.x; // OK, accessed within their declaring class
d4.x; // Error, isn't accessed through an instance of the enclosing class
~~~~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived3'.
}
}
class Derived4 extends Derived2 {
method4() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, isn't accessed through an instance of the enclosing class
~~~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'.
d1.x; // Error, isn't accessed through an instance of the enclosing class
~~~~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'.
d2.x; // Error, isn't accessed through an instance of the enclosing class
~~~~
!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'Derived4'.
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
d4.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
}
}
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, neither within their declaring class nor classes derived from their declaring class
~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
d1.x; // Error, neither within their declaring class nor classes derived from their declaring class
~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
d2.x; // Error, neither within their declaring class nor classes derived from their declaring class
~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
d3.x; // Error, neither within their declaring class nor classes derived from their declaring class
~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
d4.x; // Error, neither within their declaring class nor classes derived from their declaring class
~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
@@ -0,0 +1,206 @@
//// [protectedClassPropertyAccessibleWithinSubclass2.ts]
class Base {
protected x: string;
method() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // OK, accessed within their declaring class
d1.x; // OK, accessed within their declaring class
d2.x; // OK, accessed within their declaring class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
d4.x; // OK, accessed within their declaring class
}
}
class Derived1 extends Base {
method1() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, isn't accessed through an instance of the enclosing class
d1.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
d2.x; // Error, isn't accessed through an instance of the enclosing class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
d4.x; // Error, isn't accessed through an instance of the enclosing class
}
}
class Derived2 extends Base {
method2() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, isn't accessed through an instance of the enclosing class
d1.x; // Error, isn't accessed through an instance of the enclosing class
d2.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
d4.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class or one of its subclasses
}
}
class Derived3 extends Derived1 {
protected x: string;
method3() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, isn't accessed through an instance of the enclosing class
d1.x; // Error, isn't accessed through an instance of the enclosing class
d2.x; // Error, isn't accessed through an instance of the enclosing class
d3.x; // OK, accessed within their declaring class
d4.x; // Error, isn't accessed through an instance of the enclosing class
}
}
class Derived4 extends Derived2 {
method4() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, isn't accessed through an instance of the enclosing class
d1.x; // Error, isn't accessed through an instance of the enclosing class
d2.x; // Error, isn't accessed through an instance of the enclosing class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
d4.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
}
}
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, neither within their declaring class nor classes derived from their declaring class
d1.x; // Error, neither within their declaring class nor classes derived from their declaring class
d2.x; // Error, neither within their declaring class nor classes derived from their declaring class
d3.x; // Error, neither within their declaring class nor classes derived from their declaring class
d4.x; // Error, neither within their declaring class nor classes derived from their declaring class
//// [protectedClassPropertyAccessibleWithinSubclass2.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Base = (function () {
function Base() {
}
Base.prototype.method = function () {
var b;
var d1;
var d2;
var d3;
var d4;
b.x; // OK, accessed within their declaring class
d1.x; // OK, accessed within their declaring class
d2.x; // OK, accessed within their declaring class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
d4.x; // OK, accessed within their declaring class
};
return Base;
})();
var Derived1 = (function (_super) {
__extends(Derived1, _super);
function Derived1() {
_super.apply(this, arguments);
}
Derived1.prototype.method1 = function () {
var b;
var d1;
var d2;
var d3;
var d4;
b.x; // Error, isn't accessed through an instance of the enclosing class
d1.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
d2.x; // Error, isn't accessed through an instance of the enclosing class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
d4.x; // Error, isn't accessed through an instance of the enclosing class
};
return Derived1;
})(Base);
var Derived2 = (function (_super) {
__extends(Derived2, _super);
function Derived2() {
_super.apply(this, arguments);
}
Derived2.prototype.method2 = function () {
var b;
var d1;
var d2;
var d3;
var d4;
b.x; // Error, isn't accessed through an instance of the enclosing class
d1.x; // Error, isn't accessed through an instance of the enclosing class
d2.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
d4.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class or one of its subclasses
};
return Derived2;
})(Base);
var Derived3 = (function (_super) {
__extends(Derived3, _super);
function Derived3() {
_super.apply(this, arguments);
}
Derived3.prototype.method3 = function () {
var b;
var d1;
var d2;
var d3;
var d4;
b.x; // Error, isn't accessed through an instance of the enclosing class
d1.x; // Error, isn't accessed through an instance of the enclosing class
d2.x; // Error, isn't accessed through an instance of the enclosing class
d3.x; // OK, accessed within their declaring class
d4.x; // Error, isn't accessed through an instance of the enclosing class
};
return Derived3;
})(Derived1);
var Derived4 = (function (_super) {
__extends(Derived4, _super);
function Derived4() {
_super.apply(this, arguments);
}
Derived4.prototype.method4 = function () {
var b;
var d1;
var d2;
var d3;
var d4;
b.x; // Error, isn't accessed through an instance of the enclosing class
d1.x; // Error, isn't accessed through an instance of the enclosing class
d2.x; // Error, isn't accessed through an instance of the enclosing class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
d4.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
};
return Derived4;
})(Derived2);
var b;
var d1;
var d2;
var d3;
var d4;
b.x; // Error, neither within their declaring class nor classes derived from their declaring class
d1.x; // Error, neither within their declaring class nor classes derived from their declaring class
d2.x; // Error, neither within their declaring class nor classes derived from their declaring class
d3.x; // Error, neither within their declaring class nor classes derived from their declaring class
d4.x; // Error, neither within their declaring class nor classes derived from their declaring class
@@ -0,0 +1,19 @@
tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass3.ts(11,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword
==== tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass3.ts (1 errors) ====
class Base {
protected x: string;
method() {
this.x; // OK, accessed within their declaring class
}
}
class Derived extends Base {
method1() {
this.x; // OK, accessed within a subclass of the declaring class
super.x; // Error, x is not public
~
!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword
}
}
@@ -0,0 +1,41 @@
//// [protectedClassPropertyAccessibleWithinSubclass3.ts]
class Base {
protected x: string;
method() {
this.x; // OK, accessed within their declaring class
}
}
class Derived extends Base {
method1() {
this.x; // OK, accessed within a subclass of the declaring class
super.x; // Error, x is not public
}
}
//// [protectedClassPropertyAccessibleWithinSubclass3.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Base = (function () {
function Base() {
}
Base.prototype.method = function () {
this.x; // OK, accessed within their declaring class
};
return Base;
})();
var Derived = (function (_super) {
__extends(Derived, _super);
function Derived() {
_super.apply(this, arguments);
}
Derived.prototype.method1 = function () {
this.x; // OK, accessed within a subclass of the declaring class
_super.prototype.x; // Error, x is not public
};
return Derived;
})(Base);
@@ -0,0 +1,67 @@
tests/cases/conformance/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass.ts(7,9): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass.ts(16,9): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass.ts(25,9): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass.ts(40,1): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass.ts(41,1): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass.ts(42,1): error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
tests/cases/conformance/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass.ts(43,1): error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
==== tests/cases/conformance/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass.ts (7 errors) ====
class Base {
protected static x: string;
static staticMethod() {
Base.x; // OK, accessed within their declaring class
Derived1.x; // OK, accessed within their declaring class
Derived2.x; // OK, accessed within their declaring class
Derived3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
~~~~~~~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
}
}
class Derived1 extends Base {
static staticMethod1() {
Base.x; // OK, accessed within a class derived from their declaring class
Derived1.x; // OK, accessed within a class derived from their declaring class
Derived2.x; // OK, accessed within a class derived from their declaring class
Derived3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
~~~~~~~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
}
}
class Derived2 extends Base {
static staticMethod2() {
Base.x; // OK, accessed within a class derived from their declaring class
Derived1.x; // OK, accessed within a class derived from their declaring class
Derived2.x; // OK, accessed within a class derived from their declaring class
Derived3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
~~~~~~~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
}
}
class Derived3 extends Derived1 {
protected static x: string;
static staticMethod3() {
Base.x; // OK, accessed within a class derived from their declaring class
Derived1.x; // OK, accessed within a class derived from their declaring class
Derived2.x; // OK, accessed within a class derived from their declaring class
Derived3.x; // OK, accessed within their declaring class
}
}
Base.x; // Error, neither within their declaring class nor classes derived from their declaring class
~~~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
Derived1.x; // Error, neither within their declaring class nor classes derived from their declaring class
~~~~~~~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
Derived2.x; // Error, neither within their declaring class nor classes derived from their declaring class
~~~~~~~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Base' and its subclasses.
Derived3.x; // Error, neither within their declaring class nor classes derived from their declaring class
~~~~~~~~~~
!!! error TS2445: Property 'x' is protected and only accessible within class 'Derived3' and its subclasses.
@@ -0,0 +1,106 @@
//// [protectedStaticClassPropertyAccessibleWithinSubclass.ts]
class Base {
protected static x: string;
static staticMethod() {
Base.x; // OK, accessed within their declaring class
Derived1.x; // OK, accessed within their declaring class
Derived2.x; // OK, accessed within their declaring class
Derived3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
}
}
class Derived1 extends Base {
static staticMethod1() {
Base.x; // OK, accessed within a class derived from their declaring class
Derived1.x; // OK, accessed within a class derived from their declaring class
Derived2.x; // OK, accessed within a class derived from their declaring class
Derived3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
}
}
class Derived2 extends Base {
static staticMethod2() {
Base.x; // OK, accessed within a class derived from their declaring class
Derived1.x; // OK, accessed within a class derived from their declaring class
Derived2.x; // OK, accessed within a class derived from their declaring class
Derived3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
}
}
class Derived3 extends Derived1 {
protected static x: string;
static staticMethod3() {
Base.x; // OK, accessed within a class derived from their declaring class
Derived1.x; // OK, accessed within a class derived from their declaring class
Derived2.x; // OK, accessed within a class derived from their declaring class
Derived3.x; // OK, accessed within their declaring class
}
}
Base.x; // Error, neither within their declaring class nor classes derived from their declaring class
Derived1.x; // Error, neither within their declaring class nor classes derived from their declaring class
Derived2.x; // Error, neither within their declaring class nor classes derived from their declaring class
Derived3.x; // Error, neither within their declaring class nor classes derived from their declaring class
//// [protectedStaticClassPropertyAccessibleWithinSubclass.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Base = (function () {
function Base() {
}
Base.staticMethod = function () {
Base.x; // OK, accessed within their declaring class
Derived1.x; // OK, accessed within their declaring class
Derived2.x; // OK, accessed within their declaring class
Derived3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
};
return Base;
})();
var Derived1 = (function (_super) {
__extends(Derived1, _super);
function Derived1() {
_super.apply(this, arguments);
}
Derived1.staticMethod1 = function () {
Base.x; // OK, accessed within a class derived from their declaring class
Derived1.x; // OK, accessed within a class derived from their declaring class
Derived2.x; // OK, accessed within a class derived from their declaring class
Derived3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
};
return Derived1;
})(Base);
var Derived2 = (function (_super) {
__extends(Derived2, _super);
function Derived2() {
_super.apply(this, arguments);
}
Derived2.staticMethod2 = function () {
Base.x; // OK, accessed within a class derived from their declaring class
Derived1.x; // OK, accessed within a class derived from their declaring class
Derived2.x; // OK, accessed within a class derived from their declaring class
Derived3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
};
return Derived2;
})(Base);
var Derived3 = (function (_super) {
__extends(Derived3, _super);
function Derived3() {
_super.apply(this, arguments);
}
Derived3.staticMethod3 = function () {
Base.x; // OK, accessed within a class derived from their declaring class
Derived1.x; // OK, accessed within a class derived from their declaring class
Derived2.x; // OK, accessed within a class derived from their declaring class
Derived3.x; // OK, accessed within their declaring class
};
return Derived3;
})(Derived1);
Base.x; // Error, neither within their declaring class nor classes derived from their declaring class
Derived1.x; // Error, neither within their declaring class nor classes derived from their declaring class
Derived2.x; // Error, neither within their declaring class nor classes derived from their declaring class
Derived3.x; // Error, neither within their declaring class nor classes derived from their declaring class
@@ -0,0 +1,30 @@
tests/cases/conformance/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass2.ts(11,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword
tests/cases/conformance/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass2.ts(19,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword
==== tests/cases/conformance/classes/members/accessibility/protectedStaticClassPropertyAccessibleWithinSubclass2.ts (2 errors) ====
class Base {
protected static x: string;
static staticMethod() {
this.x; // OK, accessed within their declaring class
}
}
class Derived1 extends Base {
static staticMethod1() {
this.x; // OK, accessed within a class derived from their declaring class
super.x; // Error, x is not public
~
!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword
}
}
class Derived2 extends Derived1 {
protected static x: string;
static staticMethod3() {
this.x; // OK, accessed within a class derived from their declaring class
super.x; // Error, x is not public
~
!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword
}
}
@@ -0,0 +1,60 @@
//// [protectedStaticClassPropertyAccessibleWithinSubclass2.ts]
class Base {
protected static x: string;
static staticMethod() {
this.x; // OK, accessed within their declaring class
}
}
class Derived1 extends Base {
static staticMethod1() {
this.x; // OK, accessed within a class derived from their declaring class
super.x; // Error, x is not public
}
}
class Derived2 extends Derived1 {
protected static x: string;
static staticMethod3() {
this.x; // OK, accessed within a class derived from their declaring class
super.x; // Error, x is not public
}
}
//// [protectedStaticClassPropertyAccessibleWithinSubclass2.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Base = (function () {
function Base() {
}
Base.staticMethod = function () {
this.x; // OK, accessed within their declaring class
};
return Base;
})();
var Derived1 = (function (_super) {
__extends(Derived1, _super);
function Derived1() {
_super.apply(this, arguments);
}
Derived1.staticMethod1 = function () {
this.x; // OK, accessed within a class derived from their declaring class
_super.x; // Error, x is not public
};
return Derived1;
})(Base);
var Derived2 = (function (_super) {
__extends(Derived2, _super);
function Derived2() {
_super.apply(this, arguments);
}
Derived2.staticMethod3 = function () {
this.x; // OK, accessed within a class derived from their declaring class
_super.x; // Error, x is not public
};
return Derived2;
})(Derived1);
@@ -0,0 +1,17 @@
tests/cases/conformance/classes/members/accessibility/protectedStaticNotAccessibleInClodule.ts(10,20): error TS2445: Property 'bar' is protected and only accessible within class 'C' and its subclasses.
==== tests/cases/conformance/classes/members/accessibility/protectedStaticNotAccessibleInClodule.ts (1 errors) ====
// Any attempt to access a private property member outside the class body that contains its declaration results in a compile-time error.
class C {
public static foo: string;
protected static bar: string;
}
module C {
export var f = C.foo; // OK
export var b = C.bar; // error
~~~~~
!!! error TS2445: Property 'bar' is protected and only accessible within class 'C' and its subclasses.
}
@@ -0,0 +1,25 @@
//// [protectedStaticNotAccessibleInClodule.ts]
// Any attempt to access a private property member outside the class body that contains its declaration results in a compile-time error.
class C {
public static foo: string;
protected static bar: string;
}
module C {
export var f = C.foo; // OK
export var b = C.bar; // error
}
//// [protectedStaticNotAccessibleInClodule.js]
// Any attempt to access a private property member outside the class body that contains its declaration results in a compile-time error.
var C = (function () {
function C() {
}
return C;
})();
var C;
(function (C) {
C.f = C.foo; // OK
C.b = C.bar; // error
})(C || (C = {}));
@@ -0,0 +1,52 @@
// @declaration: true
// @target: es5
// 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) { }
}
@@ -0,0 +1,25 @@
class C1 {
constructor(public x: number) { }
}
var c1: C1;
c1.x // OK
class C2 {
constructor(private p: number) { }
}
var c2: C2;
c2.p // private, error
class C3 {
constructor(protected p: number) { }
}
var c3: C3;
c3.p // protected, error
class Derived extends C3 {
constructor(p: number) {
super(p);
this.p; // OK
}
}
@@ -0,0 +1,25 @@
class C1 {
constructor(public x?: number) { }
}
var c1: C1;
c1.x // OK
class C2 {
constructor(private p?: number) { }
}
var c2: C2;
c2.p // private, error
class C3 {
constructor(protected p?: number) { }
}
var c3: C3;
c3.p // protected, error
class Derived extends C3 {
constructor(p: number) {
super(p);
this.p; // OK
}
}
@@ -0,0 +1,13 @@
class Base {
constructor(protected p: number) { }
}
class Derived extends Base {
constructor(public p: number) {
super(p);
this.p; // OK
}
}
var d: Derived;
d.p; // public, OK
@@ -0,0 +1,94 @@
class Base {
protected x: string;
method() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // OK, accessed within their declaring class
d1.x; // OK, accessed within their declaring class
d2.x; // OK, accessed within their declaring class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
d4.x; // OK, accessed within their declaring class
}
}
class Derived1 extends Base {
method1() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, isn't accessed through an instance of the enclosing class
d1.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
d2.x; // Error, isn't accessed through an instance of the enclosing class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
d4.x; // Error, isn't accessed through an instance of the enclosing class
}
}
class Derived2 extends Base {
method2() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, isn't accessed through an instance of the enclosing class
d1.x; // Error, isn't accessed through an instance of the enclosing class
d2.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
d4.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class or one of its subclasses
}
}
class Derived3 extends Derived1 {
protected x: string;
method3() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, isn't accessed through an instance of the enclosing class
d1.x; // Error, isn't accessed through an instance of the enclosing class
d2.x; // Error, isn't accessed through an instance of the enclosing class
d3.x; // OK, accessed within their declaring class
d4.x; // Error, isn't accessed through an instance of the enclosing class
}
}
class Derived4 extends Derived2 {
method4() {
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, isn't accessed through an instance of the enclosing class
d1.x; // Error, isn't accessed through an instance of the enclosing class
d2.x; // Error, isn't accessed through an instance of the enclosing class
d3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
d4.x; // OK, accessed within a class derived from their declaring class, and through an instance of the enclosing class
}
}
var b: Base;
var d1: Derived1;
var d2: Derived2;
var d3: Derived3;
var d4: Derived4;
b.x; // Error, neither within their declaring class nor classes derived from their declaring class
d1.x; // Error, neither within their declaring class nor classes derived from their declaring class
d2.x; // Error, neither within their declaring class nor classes derived from their declaring class
d3.x; // Error, neither within their declaring class nor classes derived from their declaring class
d4.x; // Error, neither within their declaring class nor classes derived from their declaring class
@@ -0,0 +1,13 @@
class Base {
protected x: string;
method() {
this.x; // OK, accessed within their declaring class
}
}
class Derived extends Base {
method1() {
this.x; // OK, accessed within a subclass of the declaring class
super.x; // Error, x is not public
}
}
@@ -0,0 +1,43 @@
class Base {
protected static x: string;
static staticMethod() {
Base.x; // OK, accessed within their declaring class
Derived1.x; // OK, accessed within their declaring class
Derived2.x; // OK, accessed within their declaring class
Derived3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
}
}
class Derived1 extends Base {
static staticMethod1() {
Base.x; // OK, accessed within a class derived from their declaring class
Derived1.x; // OK, accessed within a class derived from their declaring class
Derived2.x; // OK, accessed within a class derived from their declaring class
Derived3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
}
}
class Derived2 extends Base {
static staticMethod2() {
Base.x; // OK, accessed within a class derived from their declaring class
Derived1.x; // OK, accessed within a class derived from their declaring class
Derived2.x; // OK, accessed within a class derived from their declaring class
Derived3.x; // Error, redefined in a subclass, can only be accessed in the declaring class or one of its subclasses
}
}
class Derived3 extends Derived1 {
protected static x: string;
static staticMethod3() {
Base.x; // OK, accessed within a class derived from their declaring class
Derived1.x; // OK, accessed within a class derived from their declaring class
Derived2.x; // OK, accessed within a class derived from their declaring class
Derived3.x; // OK, accessed within their declaring class
}
}
Base.x; // Error, neither within their declaring class nor classes derived from their declaring class
Derived1.x; // Error, neither within their declaring class nor classes derived from their declaring class
Derived2.x; // Error, neither within their declaring class nor classes derived from their declaring class
Derived3.x; // Error, neither within their declaring class nor classes derived from their declaring class
@@ -0,0 +1,21 @@
class Base {
protected static x: string;
static staticMethod() {
this.x; // OK, accessed within their declaring class
}
}
class Derived1 extends Base {
static staticMethod1() {
this.x; // OK, accessed within a class derived from their declaring class
super.x; // Error, x is not public
}
}
class Derived2 extends Derived1 {
protected static x: string;
static staticMethod3() {
this.x; // OK, accessed within a class derived from their declaring class
super.x; // Error, x is not public
}
}
@@ -0,0 +1,11 @@
// Any attempt to access a private property member outside the class body that contains its declaration results in a compile-time error.
class C {
public static foo: string;
protected static bar: string;
}
module C {
export var f = C.foo; // OK
export var b = C.bar; // error
}
@@ -0,0 +1,36 @@
// @target: ES5
var x: { foo: string; }
var y: { foo: string; bar: string; }
class Base {
protected a: typeof x;
protected b(a: typeof x) { }
protected get c() { return x; }
protected set c(v: typeof x) { }
protected d: (a: typeof x) => void;
protected static r: typeof x;
protected static s(a: typeof x) { }
protected static get t() { return x; }
protected static set t(v: typeof x) { }
protected static u: (a: typeof x) => void;
constructor(a: typeof x) { }
}
class Derived extends Base {
protected a: typeof y;
protected b(a: typeof y) { }
protected get c() { return y; }
protected set c(v: typeof y) { }
protected d: (a: typeof y) => void;
protected static r: typeof y;
protected static s(a: typeof y) { }
protected static get t() { return y; }
protected static set t(a: typeof y) { }
protected static u: (a: typeof y) => void;
constructor(a: typeof y) { super(x) }
}
@@ -0,0 +1,63 @@
// @target: ES5
var x: { foo: string; }
var y: { foo: string; bar: string; }
class Base {
protected a: typeof x;
protected b(a: typeof x) { }
protected get c() { return x; }
protected set c(v: typeof x) { }
protected d: (a: typeof x) => void ;
protected static r: typeof x;
protected static s(a: typeof x) { }
protected static get t() { return x; }
protected static set t(v: typeof x) { }
protected static u: (a: typeof x) => void ;
constructor(a: typeof x) { }
}
// Increase visibility of all protected members to public
class Derived extends Base {
a: typeof y;
b(a: typeof y) { }
get c() { return y; }
set c(v: typeof y) { }
d: (a: typeof y) => void;
static r: typeof y;
static s(a: typeof y) { }
static get t() { return y; }
static set t(a: typeof y) { }
static u: (a: typeof y) => void;
constructor(a: typeof y) { super(a); }
}
var d: Derived = new Derived(y);
var r1 = d.a;
var r2 = d.b(y);
var r3 = d.c;
var r3a = d.d;
d.c = y;
var r4 = Derived.r;
var r5 = Derived.s(y);
var r6 = Derived.t;
var r6a = Derived.u;
Derived.t = y;
class Base2 {
[i: string]: Object;
[i: number]: typeof x;
}
class Derived2 extends Base2 {
[i: string]: typeof x;
[i: number]: typeof y;
}
var d2: Derived2;
var r7 = d2[''];
var r8 = d2[1];
@@ -0,0 +1,72 @@
// @target: ES5
var x: { foo: string; }
var y: { foo: string; bar: string; }
class Base {
a: typeof x;
b(a: typeof x) { }
get c() { return x; }
set c(v: typeof x) { }
d: (a: typeof x) => void;
static r: typeof x;
static s(a: typeof x) { }
static get t() { return x; }
static set t(v: typeof x) { }
static u: (a: typeof x) => void;
constructor(a: typeof x) {}
}
// Errors
// decrease visibility of all public members to protected
class Derived1 extends Base {
protected a: typeof x;
constructor(a: typeof x) { super(a); }
}
class Derived2 extends Base {
protected b(a: typeof x) { }
constructor(a: typeof x) { super(a); }
}
class Derived3 extends Base {
protected get c() { return x; }
constructor(a: typeof x) { super(a); }
}
class Derived4 extends Base {
protected set c(v: typeof x) { }
constructor(a: typeof x) { super(a); }
}
class Derived5 extends Base {
protected d: (a: typeof x) => void ;
constructor(a: typeof x) { super(a); }
}
class Derived6 extends Base {
protected static r: typeof x;
constructor(a: typeof x) { super(a); }
}
class Derived7 extends Base {
protected static s(a: typeof x) { }
constructor(a: typeof x) { super(a); }
}
class Derived8 extends Base {
protected static get t() { return x; }
constructor(a: typeof x) { super(a); }
}
class Derived9 extends Base {
protected static set t(v: typeof x) { }
constructor(a: typeof x) { super(a); }
}
class Derived10 extends Base {
protected static u: (a: typeof x) => void ;
constructor(a: typeof x) { super(a); }
}
@@ -0,0 +1,14 @@
var x: { foo: string; }
var y: { foo: string; bar: string; }
class Base {
protected a: typeof x;
}
class Derived1 extends Base {
public a: typeof x;
}
class Derived2 extends Derived1 {
protected a: typeof x; // Error, parent was public
}
@@ -0,0 +1,20 @@
// subclassing is not transitive when you can remove required parameters and add optional parameters on protected members
class C {
protected foo(x: number) { }
}
class D extends C {
protected foo() { } // ok to drop parameters
}
class E extends D {
public foo(x?: string) { } // ok to add optional parameters
}
var c: C;
var d: D;
var e: E;
c = e;
var r = c.foo(1);
var r2 = e.foo('');
@@ -0,0 +1,22 @@
// @target: ES5
class Base {
protected x: string;
protected fn(): string {
return '';
}
protected get a() { return 1; }
protected set a(v) { }
}
// error, not a subtype
class Derived extends Base {
private x: string;
private fn(): string {
return '';
}
private get a() { return 1; }
private set a(v) { }
}
@@ -0,0 +1,22 @@
// @target: ES5
class Base {
protected static x: string;
protected static fn(): string {
return '';
}
protected static get a() { return 1; }
protected static set a(v) { }
}
// should be error
class Derived extends Base {
private static x: string;
private static fn(): string {
return '';
}
private static get a() { return 1; }
private static set a(v) { }
}
@@ -0,0 +1,45 @@
// @target: ES5
// No errors
class C {
private static privateProperty;
private static privateMethod() { }
private static get privateGetter() { return 0; }
private static set privateSetter(a: number) { }
protected static protectedProperty;
protected static protectedMethod() { }
protected static get protectedGetter() { return 0; }
protected static set protectedSetter(a: number) { }
public static publicProperty;
public static publicMethod() { }
public static get publicGetter() { return 0; }
public static set publicSetter(a: number) { }
}
// Errors, accessibility modifiers must precede static
class D {
static private privateProperty;
static private privateMethod() { }
static private get privateGetter() { return 0; }
static private set privateSetter(a: number) { }
static protected protectedProperty;
static protected protectedMethod() { }
static protected get protectedGetter() { return 0; }
static protected set protectedSetter(a: number) { }
static public publicProperty;
static public publicMethod() { }
static public get publicGetter() { return 0; }
static public set publicSetter(a: number) { }
}
// Errors, multiple accessibility modifier
class E {
private public protected property;
public protected method() { }
private protected get getter() { return 0; }
public public set setter(a: number) { }
}
@@ -0,0 +1,33 @@
// @target: ES5
class C {
get x() {
return 1;
}
private set x(v) {
}
}
class D {
protected get x() {
return 1;
}
private set x(v) {
}
}
class E {
protected set x(v) {
}
get x() {
return 1;
}
}
class F {
protected static set x(v) {
}
static get x() {
return 1;
}
}
@@ -12,10 +12,19 @@ class C {
public static foo(x: number, y: string); // error
private static foo(x: any, y?: any) { }
protected baz(x: string); // error
protected baz(x: number, y: string); // error
private baz(x: any, y?: any) { }
private static bar(x: 'hi');
public static bar(x: string); // error
private static bar(x: number, y: string);
private static bar(x: any, y?: any) { }
protected static baz(x: 'hi');
public static baz(x: string); // error
protected static baz(x: number, y: string);
protected static baz(x: any, y?: any) { }
}
class D<T> {
@@ -28,6 +37,10 @@ class D<T> {
private bar(x: T, y: T);
private bar(x: any, y?: any) { }
private baz(x: string);
protected baz(x: number, y: string); // error
private baz(x: any, y?: any) { }
private static foo(x: number);
public static foo(x: number, y: string); // error
private static foo(x: any, y?: any) { }
@@ -36,6 +49,10 @@ class D<T> {
public static bar(x: string); // error
private static bar(x: number, y: string);
private static bar(x: any, y?: any) { }
public static baz(x: string); // error
protected static baz(x: number, y: string);
protected static baz(x: any, y?: any) { }
}
var c: C;
@@ -0,0 +1,6 @@
// Errors
interface Foo {
public a: any;
private b: any;
protected c: any;
}
@@ -0,0 +1,27 @@
// accessing any private outside the class is an error
class C {
protected x;
protected a = '';
protected b: string = '';
protected c() { return '' }
protected d = () => '';
protected static e;
protected static f() { return '' }
protected static g = () => '';
}
class D extends C {
method() {
// No errors
var d = new D();
var r1: string = d.x;
var r2: string = d.a;
var r3: string = d.b;
var r4: string = d.c();
var r5: string = d.d();
var r6: string = C.e;
var r7: string = C.f();
var r8: string = C.g();
}
}