1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(9,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(17,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(23,13): error TS2331: 'this' cannot be referenced in a module or namespace body.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(31,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(33,25): error TS2507: Type 'undefined' is not a constructor function type.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(39,9): error TS2332: 'this' cannot be referenced in current location.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(40,9): error TS2332: 'this' cannot be referenced in current location.
==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (7 errors) ====
class BaseErrClass {
constructor(t: any) { }
}
class ClassWithNoInitializer extends BaseErrClass {
t;
//'this' in optional super call
constructor() {
super(this); // error: "super" has to be called before "this" accessing
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
}
}
class ClassWithInitializer extends BaseErrClass {
t = 4;
//'this' in required super call
constructor() {
super(this); // Error
~~~~
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
}
}
module M {
//'this' in module variable
var x = this; // Error
~~~~
!!! error TS2331: 'this' cannot be referenced in a module or namespace body.
}
//'this' as type parameter constraint
// function fn<T extends this >() { } // Error
//'this' as a type argument
function genericFunc<T>(x: T) { }
genericFunc<this>(undefined); // Should be an error
~~~~
!!! error TS2526: A 'this' type is available only in a non-static member of a class or interface.
class ErrClass3 extends this {
~~~~
!!! error TS2507: Type 'undefined' is not a constructor function type.
}
//'this' as a computed enum value
enum SomeEnum {
A = this, // Should not be allowed
~~~~
!!! error TS2332: 'this' cannot be referenced in current location.
B = this.spaaaace // Also should not be allowed
~~~~
!!! error TS2332: 'this' cannot be referenced in current location.
}
export = this; // Should be an error
|