mirror of
https://github.com/swc-project/swc.git
synced 2024-12-22 21:21:31 +03:00
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
// @declaration: true
|
|
|
|
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
|
|
constructor(public x: number) { super(x); }
|
|
createInstance() { new DerivedC(9); }
|
|
createBaseInstance() { new BaseC(10); } // error
|
|
static staticBaseInstance() { new BaseC(11); } // error
|
|
}
|
|
|
|
var ba = new BaseA(1);
|
|
var bb = new BaseB(1); // error
|
|
var bc = new BaseC(1); // error
|
|
|
|
var da = new DerivedA(1);
|
|
var db = new DerivedB(1);
|
|
var dc = new DerivedC(1);
|