2014-09-12 22:35:07 +02:00
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS2332: 'this' cannot be referenced in current location.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(28,13): error TS2331: 'this' cannot be referenced in a module body.
2014-12-17 00:56:56 +01:00
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(38,25): error TS1133: Type reference expected.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(38,30): error TS1005: ';' expected.
2014-09-12 22:35:07 +02:00
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(44,9): error TS2332: 'this' cannot be referenced in current location.
tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): error TS2332: 'this' cannot be referenced in current location.
2014-07-13 01:04:16 +02:00
==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (7 errors) ====
//'this' in static member initializer
class ErrClass1 {
static t = this; // Error
~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2334: 'this' cannot be referenced in a static property initializer.
2014-07-13 01:04:16 +02:00
}
class BaseErrClass {
constructor(t: any) { }
}
class ClassWithNoInitializer extends BaseErrClass {
t;
//'this' in optional super call
constructor() {
super(this); // OK
}
}
class ClassWithInitializer extends BaseErrClass {
t = 4;
//'this' in required super call
constructor() {
super(this); // Error
~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2332: 'this' cannot be referenced in current location.
2014-07-13 01:04:16 +02:00
}
}
module M {
//'this' in module variable
var x = this; // Error
~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2331: 'this' cannot be referenced in a module body.
2014-07-13 01:04:16 +02:00
}
//'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
class ErrClass3 extends this {
~~~~
2014-12-01 00:38:45 +01:00
!!! error TS1133: Type reference expected.
2014-07-13 01:04:16 +02:00
~
2014-09-12 00:19:57 +02:00
!!! error TS1005: ';' expected.
2014-07-13 01:04:16 +02:00
}
//'this' as a computed enum value
enum SomeEnum {
A = this, // Should not be allowed
~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2332: 'this' cannot be referenced in current location.
2014-07-13 01:04:16 +02:00
B = this.spaaaace // Also should not be allowed
~~~~
2014-09-12 00:19:57 +02:00
!!! error TS2332: 'this' cannot be referenced in current location.
2014-07-13 01:04:16 +02:00
}