mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
138 lines
7.4 KiB
Plaintext
138 lines
7.4 KiB
Plaintext
checkSuperCallBeforeThisAccess.ts(7,18): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
checkSuperCallBeforeThisAccess.ts(8,18): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
checkSuperCallBeforeThisAccess.ts(9,18): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
|
|
checkSuperCallBeforeThisAccess.ts(9,24): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
|
|
checkSuperCallBeforeThisAccess.ts(12,30): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
|
|
checkSuperCallBeforeThisAccess.ts(17,28): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
|
|
checkSuperCallBeforeThisAccess.ts(20,22): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
checkSuperCallBeforeThisAccess.ts(21,22): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
checkSuperCallBeforeThisAccess.ts(22,22): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
|
|
checkSuperCallBeforeThisAccess.ts(22,28): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
|
|
checkSuperCallBeforeThisAccess.ts(30,30): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
checkSuperCallBeforeThisAccess.ts(39,22): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
checkSuperCallBeforeThisAccess.ts(43,18): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
checkSuperCallBeforeThisAccess.ts(44,18): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
checkSuperCallBeforeThisAccess.ts(45,18): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
|
|
checkSuperCallBeforeThisAccess.ts(45,24): error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
|
|
checkSuperCallBeforeThisAccess.ts(59,27): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
checkSuperCallBeforeThisAccess.ts(75,27): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
|
|
|
|
==== checkSuperCallBeforeThisAccess.ts (18 errors) ====
|
|
class A {
|
|
x = 1;
|
|
}
|
|
|
|
class C1 extends A {
|
|
constructor(n: number) {
|
|
let a1 = this; // Error
|
|
~~~~
|
|
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
let a2 = this.x; // Error
|
|
~~~~
|
|
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
let a3 = super.x; // Error
|
|
~~~~~
|
|
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
|
|
~
|
|
!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
|
|
let a4 = () => this;
|
|
let a5 = () => this.x;
|
|
let a6 = () => super.x;
|
|
~
|
|
!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
|
|
if (!!true) {
|
|
super();
|
|
let b1 = this;
|
|
let b2 = this.x;
|
|
let b3 = super.x;
|
|
~
|
|
!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
|
|
}
|
|
else {
|
|
let c1 = this; // Error
|
|
~~~~
|
|
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
let c2 = this.x; // Error
|
|
~~~~
|
|
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
let c3 = super.x; // Error
|
|
~~~~~
|
|
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
|
|
~
|
|
!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
|
|
}
|
|
if (!!true) {
|
|
switch (n) {
|
|
case 1:
|
|
super();
|
|
let d1 = this.x;
|
|
case 2:
|
|
let d2 = this.x; // Error
|
|
~~~~
|
|
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
default:
|
|
super();
|
|
let d3 = this.x;
|
|
}
|
|
let d4 = this.x;
|
|
}
|
|
if (!!true) {
|
|
let e1 = { w: !!true ? super() : 0 };
|
|
let e2 = this.x; // Error
|
|
~~~~
|
|
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
let e3 = { w: !!true ? super() : super() };
|
|
let e4 = this.x;
|
|
}
|
|
let f1 = this; // Error
|
|
~~~~
|
|
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
let f2 = this.x; // Error
|
|
~~~~
|
|
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
let f3 = super.x; // Error
|
|
~~~~~
|
|
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
|
|
~
|
|
!!! error TS2855: Class field 'x' defined by the parent class is not accessible in the child class via super.
|
|
}
|
|
}
|
|
|
|
// Repro from #38512
|
|
|
|
export class Foo {
|
|
constructor(value: number) {
|
|
}
|
|
}
|
|
|
|
export class BarCorrectlyFails extends Foo {
|
|
constructor(something: boolean) {
|
|
if (!something) {
|
|
const value = this.bar(); // Error
|
|
~~~~
|
|
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
super(value);
|
|
}
|
|
else {
|
|
super(1337);
|
|
}
|
|
}
|
|
bar(): number { return 4; }
|
|
}
|
|
|
|
export class BarIncorrectlyWorks extends Foo {
|
|
constructor(something: boolean) {
|
|
if (something) {
|
|
super(1337);
|
|
}
|
|
else {
|
|
const value = this.bar(); // Error
|
|
~~~~
|
|
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
|
|
super(value);
|
|
}
|
|
}
|
|
bar(): number { return 4; }
|
|
}
|
|
|