Shorten error spans for errors reported on constructor declarations (#58061)

This commit is contained in:
Mateusz Burzyński
2024-05-31 12:31:38 -07:00
committed by GitHub
parent 40583ff9df
commit 7f7ff923c9
37 changed files with 114 additions and 232 deletions
+11
View File
@@ -2309,6 +2309,17 @@ export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpa
const pos = skipTrivia(sourceFile.text, (node as JSDocSatisfiesTag).tagName.pos);
return getSpanOfTokenAtPosition(sourceFile, pos);
}
case SyntaxKind.Constructor: {
const constructorDeclaration = node as ConstructorDeclaration;
const start = skipTrivia(sourceFile.text, constructorDeclaration.pos);
const scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.languageVariant, sourceFile.text, /*onError*/ undefined, start);
let token = scanner.scan();
while (token !== SyntaxKind.ConstructorKeyword && token !== SyntaxKind.EndOfFileToken) {
token = scanner.scan();
}
const end = scanner.getTokenEnd();
return createTextSpanFromBounds(start, end);
}
}
if (errorNode === undefined) {
@@ -5,7 +5,7 @@ ClassDeclaration10.ts(3,4): error TS2391: Function implementation is missing or
==== ClassDeclaration10.ts (2 errors) ====
class C {
constructor();
~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2390: Constructor implementation is missing.
foo();
~~~
@@ -4,7 +4,7 @@ ClassDeclaration11.ts(2,4): error TS2390: Constructor implementation is missing.
==== ClassDeclaration11.ts (1 errors) ====
class C {
constructor();
~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2390: Constructor implementation is missing.
foo() { }
}
@@ -8,6 +8,6 @@ ClassDeclaration14.ts(3,4): error TS2390: Constructor implementation is missing.
~~~
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
constructor();
~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2390: Constructor implementation is missing.
}
@@ -4,6 +4,6 @@ ClassDeclaration8.ts(2,3): error TS2390: Constructor implementation is missing.
==== ClassDeclaration8.ts (1 errors) ====
class C {
constructor();
~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2390: Constructor implementation is missing.
}
+2 -4
View File
@@ -35,9 +35,9 @@ bases.ts(18,9): error TS2339: Property 'y' does not exist on type 'C'.
!!! error TS2420: Property 'x' is missing in type 'C' but required in type 'I'.
!!! related TS2728 bases.ts:2:5: 'x' is declared here.
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
this.x: any;
~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
~
@@ -47,8 +47,6 @@ bases.ts(18,9): error TS2339: Property 'y' does not exist on type 'C'.
~~~
!!! error TS2693: 'any' only refers to a type, but is being used as a value here.
}
~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
}
new C().x;
@@ -6,10 +6,10 @@ classConstructorOverloadsAccessibility.ts(11,2): error TS2385: Overload signatur
==== classConstructorOverloadsAccessibility.ts (3 errors) ====
class A {
public constructor(a: boolean) // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~
!!! error TS2385: Overload signatures must all be public, private or protected.
protected constructor(a: number) // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2385: Overload signatures must all be public, private or protected.
private constructor(a: string)
private constructor() {
@@ -19,7 +19,7 @@ classConstructorOverloadsAccessibility.ts(11,2): error TS2385: Overload signatur
class B {
protected constructor(a: number) // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2385: Overload signatures must all be public, private or protected.
constructor(a: string)
constructor() {
@@ -53,7 +53,7 @@ classUpdateTests.ts(113,1): error TS1128: Declaration or statement expected.
class F extends E {
constructor() {} // ERROR - super call required
~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
}
@@ -7,18 +7,18 @@ classWithTwoConstructorDefinitions.ts(8,5): error TS2392: Multiple constructor i
==== classWithTwoConstructorDefinitions.ts (4 errors) ====
class C {
constructor() { } // error
~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
constructor(x) { } // error
~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
}
class D<T> {
constructor(x: T) { } // error
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
constructor(x: T, y: T) { } // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
}
@@ -17,25 +17,21 @@ constructorOverloads1.ts(17,18): error TS2769: No overload matches this call.
==== constructorOverloads1.ts (6 errors) ====
class Foo {
constructor(s: string);
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
constructor(n: number);
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
constructor(x: any) {
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
}
~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
constructor(x: any) {
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
}
~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
bar1() { /*WScript.Echo("bar1");*/ }
bar2() { /*WScript.Echo("bar1");*/ }
}
@@ -14,7 +14,7 @@ constructorOverloads3.ts(12,5): error TS2377: Constructors for derived classes m
constructor(n: number);
constructor(a: any);
constructor(x: any, y?: any) { }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
bar1() { /*WScript.Echo("Yo");*/}
}
@@ -5,10 +5,10 @@ constructorOverloads8.ts(3,5): error TS2392: Multiple constructor implementation
==== constructorOverloads8.ts (2 errors) ====
class C {
constructor(x) { }
~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
constructor(y, x) { } // illegal, 2 constructor implementations
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
}
@@ -476,7 +476,7 @@ constructorWithIncompleteTypeAnnotation.ts(261,1): error TS1128: Declaration or
private otherValue = 42;
constructor(private value: number, public name: string) : }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2390: Constructor implementation is missing.
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2369: A parameter property is only allowed in a constructor implementation.
@@ -21,7 +21,7 @@ constructorsWithSpecializedSignatures.ts(26,5): error TS2394: This overload sign
class D {
constructor(x: "hi");
constructor(x: "foo");
~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2394: This overload signature is not compatible with its implementation signature.
!!! related TS2750 constructorsWithSpecializedSignatures.ts:20:5: The implementation signature is declared here.
constructor(x: number);
@@ -32,7 +32,7 @@ constructorsWithSpecializedSignatures.ts(26,5): error TS2394: This overload sign
class D2 {
constructor(x: "hi");
constructor(x: "foo");
~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2394: This overload signature is not compatible with its implementation signature.
!!! related TS2750 constructorsWithSpecializedSignatures.ts:28:5: The implementation signature is declared here.
constructor(x: string);
@@ -14,10 +14,9 @@ derivedClassConstructorWithoutSuperCall.ts(24,31): error TS2337: Super calls are
class Derived extends Base {
constructor() { // error
~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
}
}
class Base2<T> {
@@ -26,26 +25,22 @@ derivedClassConstructorWithoutSuperCall.ts(24,31): error TS2337: Super calls are
class Derived2<T> extends Base2<T> {
constructor() { // error for no super call (nested scopes don't count)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
var r2 = () => super(); // error for misplaced super call (nested function)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
}
~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
}
class Derived3<T> extends Base2<T> {
constructor() { // error
~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
var r = function () { super() } // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
}
~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
}
class Derived4<T> extends Base2<T> {
@@ -66,20 +66,16 @@ derivedClassParameterProperties.ts(81,9): error TS17009: 'super' must be called
a = 1;
b: number;
constructor(y: string) {
~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
this.a = 3;
~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
this.b = 3;
~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
super();
~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class Derived8 extends Base {
@@ -99,20 +95,16 @@ derivedClassParameterProperties.ts(81,9): error TS17009: 'super' must be called
a = 1;
b: number;
constructor(y: string) {
~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
this.a = 3;
~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
this.b = 3;
~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
super();
~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class Derived10<T> extends Base2<T> {
@@ -58,69 +58,57 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r
class Derived1 extends Base {
prop = true;
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
super.receivesAnything();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
super();
~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class Derived2 extends Base {
prop = true;
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
super.receivesAnything(this);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
super();
~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class Derived3 extends Base {
prop = true;
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
super.receivesAnything();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
super(this);
~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class Derived4 extends Base {
prop = true;
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
super.receivesAnything(this);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
super(this);
~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class Derived5 extends Base {
@@ -178,43 +166,31 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r
class DerivedWithDecoratorOnClass extends Base {
prop = true;
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
@decorate(this)
~~~~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
class InnerClass { }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
super();
~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class DerivedWithDecoratorOnClassMethod extends Base {
prop = true;
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
class InnerClass {
~~~~~~~~~~~~~~~~~~~~~~~~~~
@decorate(this)
~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
innerMethod() { }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~
super();
~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class DerivedWithDecoratorOnClassProperty extends Base {
@@ -271,16 +247,13 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r
class DerivedWithParenthesisAfterStatement extends Base {
prop = true;
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
this.prop;
~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
(super());
~~~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class DerivedWithParenthesisBeforeStatement extends Base {
@@ -311,36 +284,23 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r
class DerivedWithClassDeclarationExtendingMember extends Base {
memberClass = class { };
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
class InnerClass extends this.memberClass {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
private method() {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
return this;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
private property = 7;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
constructor() {
~~~~~~~~~~~~~~~~~~~~~~~~~~~
super();
~~~~~~~~~~~~~~~~~~~~~~~~
this.property;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
this.method();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
}
~~~~~~~~~
super();
~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class DerivedWithClassExpression extends Base {
@@ -363,16 +323,13 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r
class DerivedWithClassExpressionExtendingMember extends Base {
memberClass = class { };
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
console.log(class extends this.memberClass { });
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
super();
~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class DerivedWithDerivedClassExpression extends Base {
@@ -421,34 +378,23 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r
class DerivedWithObjectAccessorsUsingThisInKeys extends Base {
propName = "prop";
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
const obj = {
~~~~~~~~~~~~~~~~~~~~~
_prop: "prop",
~~~~~~~~~~~~~~~~~~~~~~~~~~
get [this.propName]() {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
return true;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
},
~~~~~~~~~~~~~~
set [this.propName](param) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
this._prop = param;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
};
~~~~~~~~~~
super();
~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class DerivedWithObjectAccessorsUsingThisInBodies extends Base {
@@ -470,39 +416,29 @@ derivedClassSuperProperties.ts(397,21): error TS2401: A 'super' call must be a r
class DerivedWithObjectComputedPropertyBody extends Base {
propName = "prop";
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
const obj = {
~~~~~~~~~~~~~~~~~~~~~
prop: this.propName,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
};
~~~~~~~~~~
super();
~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class DerivedWithObjectComputedPropertyName extends Base {
propName = "prop";
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
const obj = {
~~~~~~~~~~~~~~~~~~~~~
[this.propName]: true,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
};
~~~~~~~~~~
super();
~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class DerivedWithObjectMethod extends Base {
@@ -42,7 +42,7 @@ externModule.ts(37,3): error TS2552: Cannot find name 'XDate'. Did you mean 'Dat
constructor(year: number, month: number, date: number, hours: number, minutes: number, seconds: number, ms: number);
constructor(value: number);
constructor();
~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2390: Constructor implementation is missing.
static parse(string: string): number;
@@ -13,42 +13,29 @@ illegalSuperCallsInConstructor.ts(16,17): error TS2337: Super calls are not perm
class Derived extends Base {
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
var r2 = () => super();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
var r3 = () => { super(); }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
var r4 = function () { super(); }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
var r5 = {
~~~~~~~~~~~~~~~~~~
get foo() {
~~~~~~~~~~~~~~~~~~~~~~~
super();
~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
return 1;
~~~~~~~~~~~~~~~~~~~~~~~~~
},
~~~~~~~~~~~~~~
set foo(v: number) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
super();
~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.
}
~~~~~~~~~~~~~
}
~~~~~~~~~
}
~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
}
@@ -4,7 +4,7 @@ a.js(2,3): error TS8017: Signature declarations can only be used in TypeScript f
==== a.js (1 errors) ====
class A {
constructor();
~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS8017: Signature declarations can only be used in TypeScript files.
}
@@ -7,7 +7,7 @@ parameterPropertyInConstructor2.ts(4,24): error TS2300: Duplicate identifier 'na
module mod {
class Customers {
constructor(public names: string);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2394: This overload signature is not compatible with its implementation signature.
!!! related TS2750 parameterPropertyInConstructor2.ts:4:5: The implementation signature is declared here.
~~~~~~~~~~~~~~~~~~~~
@@ -5,7 +5,7 @@ parserClassDeclaration10.ts(3,4): error TS2391: Function implementation is missi
==== parserClassDeclaration10.ts (2 errors) ====
class C {
constructor();
~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2390: Constructor implementation is missing.
foo();
~~~
@@ -4,7 +4,7 @@ parserClassDeclaration11.ts(2,4): error TS2390: Constructor implementation is mi
==== parserClassDeclaration11.ts (1 errors) ====
class C {
constructor();
~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2390: Constructor implementation is missing.
foo() { }
}
@@ -4,7 +4,7 @@ parserClassDeclaration12.ts(2,4): error TS2394: This overload signature is not c
==== parserClassDeclaration12.ts (1 errors) ====
class C {
constructor();
~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2394: This overload signature is not compatible with its implementation signature.
!!! related TS2750 parserClassDeclaration12.ts:3:4: The implementation signature is declared here.
constructor(a) { }
@@ -8,6 +8,6 @@ parserClassDeclaration14.ts(3,4): error TS2390: Constructor implementation is mi
~~~
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
constructor();
~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2390: Constructor implementation is missing.
}
@@ -4,6 +4,6 @@ parserClassDeclaration8.ts(2,3): error TS2390: Constructor implementation is mis
==== parserClassDeclaration8.ts (1 errors) ====
class C {
constructor();
~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2390: Constructor implementation is missing.
}
@@ -27,56 +27,56 @@ parserConstructorDeclaration12.ts(9,16): error TS1092: Type parameters cannot ap
==== parserConstructorDeclaration12.ts (24 errors) ====
class C {
constructor<>() { }
~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
~~
!!! error TS1098: Type parameter list cannot be empty.
!!! error TS1092: Type parameters cannot appear on a constructor declaration.
constructor<> () { }
~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
~~
!!! error TS1098: Type parameter list cannot be empty.
!!! error TS1092: Type parameters cannot appear on a constructor declaration.
constructor <>() { }
~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
~~
!!! error TS1098: Type parameter list cannot be empty.
!!! error TS1092: Type parameters cannot appear on a constructor declaration.
constructor <> () { }
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
~~
!!! error TS1098: Type parameter list cannot be empty.
!!! error TS1092: Type parameters cannot appear on a constructor declaration.
constructor< >() { }
~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
~~~
!!! error TS1098: Type parameter list cannot be empty.
!!! error TS1092: Type parameters cannot appear on a constructor declaration.
constructor< > () { }
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
~~~
!!! error TS1098: Type parameter list cannot be empty.
!!! error TS1092: Type parameters cannot appear on a constructor declaration.
constructor < >() { }
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
~~~
!!! error TS1098: Type parameter list cannot be empty.
!!! error TS1092: Type parameters cannot appear on a constructor declaration.
constructor < > () { }
~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2392: Multiple constructor implementations are not allowed.
~~~
!!! error TS1098: Type parameter list cannot be empty.
@@ -6,7 +6,7 @@ parserConstructorDeclaration8.ts(3,21): error TS1005: '(' expected.
class C {
// Not a constructor
public constructor;
~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~
!!! error TS2390: Constructor implementation is missing.
~
!!! error TS1005: '(' expected.
@@ -5,7 +5,7 @@ parserParameterList17.ts(2,16): error TS2371: A parameter initializer is only al
==== parserParameterList17.ts (2 errors) ====
class C {
constructor(a = 4);
~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2394: This overload signature is not compatible with its implementation signature.
!!! related TS2750 parserParameterList17.ts:3:4: The implementation signature is declared here.
~~~~~
@@ -7,14 +7,11 @@ privateNameBadSuper.ts(5,5): error TS17009: 'super' must be called before access
class A extends B {
#x;
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
this;
~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
super();
~~~~~~~~~~~~
}
~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
@@ -20,34 +20,28 @@ staticPropSuper.ts(32,5): error TS2377: Constructors for derived classes must co
public p: number = 10;
constructor() {
~~~~~~~~~~~~~~~
var x = 1; // should error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
var x = 1; // should error
}
}
class D extends A {
private p: number = 11;
constructor() {
~~~~~~~~~~~~~~~
var x = 1; // should error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
var x = 1; // should error
}
}
class E extends A {
p: number = 12;
constructor() {
~~~~~~~~~~~~~~~
var x = 1; // should error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
var x = 1; // should error
}
}
@@ -30,20 +30,15 @@ strictModeInConstructor.ts(29,17): error TS17009: 'super' must be called before
public s: number = 9;
constructor () {
~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
var x = 1; // No error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var y = this.s; // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
super();
~~~~~~~~~~~~~~~~
"use strict";
~~~~~~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2376: A 'super' call must be the first statement in the constructor to refer to 'super' or 'this' when a derived class contains initialized properties, parameter properties, or private identifiers.
}
class Bs extends A {
@@ -10,20 +10,13 @@ superCallInsideClassDeclaration.ts(8,5): error TS2377: Constructors for derived
class B extends A {
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
class D extends C {
~~~~~~~~~~~~~~~~~~~~~~~~~~~
constructor() {
~~~~~~~~~~~~~~~~~~~~~~~~~~~
super();
~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
}
~~~~~~~~~
}
~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
}
@@ -10,20 +10,13 @@ superCallInsideClassExpression.ts(8,5): error TS2377: Constructors for derived c
class B extends A {
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
var D = class extends C {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
constructor() {
~~~~~~~~~~~~~~~~~~~~~~~~~~~
super();
~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~~~~~
}
~~~~~~~~~
}
~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
}
@@ -12,12 +12,11 @@ superInConstructorParam1.ts(8,19): error TS17011: 'super' must be called before
class C extends B {
constructor(a = super.foo()) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
~~~~~
!!! error TS2336: 'super' cannot be referenced in constructor arguments.
~~~~~
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
}
~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
}
@@ -13,15 +13,13 @@ superNewCall1.ts(9,13): error TS17011: 'super' must be called before accessing a
class B extends A<number, string> {
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
new super(value => String(value));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS2351: This expression is not constructable.
!!! error TS2351: Type 'A<number, string>' has no construct signatures.
~~~~~
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
}
~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
}
@@ -49,9 +49,9 @@ taggedTemplatesWithTypeArguments2.ts(36,34): error TS1034: 'super' must be follo
class SomeDerived<T> extends SomeBase<number, string, T> {
constructor() {
~~~~~~~~~~~~~~~
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
super<number, string, T> `hello world`;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
~~~~~~~~~~~~~~~~~~~
@@ -59,6 +59,4 @@ taggedTemplatesWithTypeArguments2.ts(36,34): error TS1034: 'super' must be follo
~~~~~~~~~~~~~
!!! error TS1034: 'super' must be followed by an argument list or member access.
}
~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
}