48 lines
No EOL
1.7 KiB
Text
48 lines
No EOL
1.7 KiB
Text
==== tests/cases/conformance/classes/constructorDeclarations/superCalls/derivedClassConstructorWithoutSuperCall.ts (5 errors) ====
|
|
// derived class constructors must contain a super call
|
|
|
|
class Base {
|
|
x: string;
|
|
}
|
|
|
|
class Derived extends Base {
|
|
constructor() { // error
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
}
|
|
~~~~~
|
|
!!! Constructors for derived classes must contain a 'super' call.
|
|
}
|
|
|
|
class Base2<T> {
|
|
x: T;
|
|
}
|
|
|
|
class Derived2<T> extends Base2<T> {
|
|
constructor() { // error for no super call (nested scopes don't count)
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
var r2 = () => super(); // error for misplaced super call (nested function)
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
~~~~~
|
|
!!! Super calls are not permitted outside constructors or in nested functions inside constructors
|
|
}
|
|
~~~~~
|
|
!!! Constructors for derived classes must contain a 'super' call.
|
|
}
|
|
|
|
class Derived3<T> extends Base2<T> {
|
|
constructor() { // error
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
var r = function () { super() } // error
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
~~~~~
|
|
!!! Super calls are not permitted outside constructors or in nested functions inside constructors
|
|
}
|
|
~~~~~
|
|
!!! Constructors for derived classes must contain a 'super' call.
|
|
}
|
|
|
|
class Derived4<T> extends Base2<T> {
|
|
constructor() {
|
|
var r = super(); // ok
|
|
}
|
|
} |