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 68 69 70 71 72
|
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,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(44,9): error TS2332: 'this' cannot be referenced in current location.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(45,9): error TS2332: 'this' cannot be referenced in current location.
==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (7 errors) ====
//'this' in static member initializer
class ErrClass1 {
static t = this; // Error
~~~~
!!! error TS2334: 'this' cannot be referenced in a static property initializer.
}
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 {
}
//'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
|