mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
63 lines
2.9 KiB
Plaintext
63 lines
2.9 KiB
Plaintext
classConstructorAccessibility2.ts(31,24): error TS2675: Cannot extend a class 'BaseC'. Class constructor is marked as private.
|
|
classConstructorAccessibility2.ts(34,28): error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration.
|
|
classConstructorAccessibility2.ts(35,35): error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration.
|
|
classConstructorAccessibility2.ts(39,10): error TS2674: Constructor of class 'BaseB' is protected and only accessible within the class declaration.
|
|
classConstructorAccessibility2.ts(40,10): error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration.
|
|
|
|
|
|
==== classConstructorAccessibility2.ts (5 errors) ====
|
|
class BaseA {
|
|
public constructor(public x: number) { }
|
|
createInstance() { new BaseA(1); }
|
|
}
|
|
|
|
class BaseB {
|
|
protected constructor(public x: number) { }
|
|
createInstance() { new BaseB(2); }
|
|
}
|
|
|
|
class BaseC {
|
|
private constructor(public x: number) { }
|
|
createInstance() { new BaseC(3); }
|
|
static staticInstance() { new BaseC(4); }
|
|
}
|
|
|
|
class DerivedA extends BaseA {
|
|
constructor(public x: number) { super(x); }
|
|
createInstance() { new DerivedA(5); }
|
|
createBaseInstance() { new BaseA(6); }
|
|
static staticBaseInstance() { new BaseA(7); }
|
|
}
|
|
|
|
class DerivedB extends BaseB {
|
|
constructor(public x: number) { super(x); }
|
|
createInstance() { new DerivedB(7); }
|
|
createBaseInstance() { new BaseB(8); } // ok
|
|
static staticBaseInstance() { new BaseB(9); } // ok
|
|
}
|
|
|
|
class DerivedC extends BaseC { // error
|
|
~~~~~
|
|
!!! error TS2675: Cannot extend a class 'BaseC'. Class constructor is marked as private.
|
|
constructor(public x: number) { super(x); }
|
|
createInstance() { new DerivedC(9); }
|
|
createBaseInstance() { new BaseC(10); } // error
|
|
~~~~~~~~~~~~~
|
|
!!! error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration.
|
|
static staticBaseInstance() { new BaseC(11); } // error
|
|
~~~~~~~~~~~~~
|
|
!!! error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration.
|
|
}
|
|
|
|
var ba = new BaseA(1);
|
|
var bb = new BaseB(1); // error
|
|
~~~~~~~~~~~~
|
|
!!! error TS2674: Constructor of class 'BaseB' is protected and only accessible within the class declaration.
|
|
var bc = new BaseC(1); // error
|
|
~~~~~~~~~~~~
|
|
!!! error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration.
|
|
|
|
var da = new DerivedA(1);
|
|
var db = new DerivedB(1);
|
|
var dc = new DerivedC(1);
|
|
|