Previously, `this` was implicitly typed by the shape of its containing object literal. This is not correct for JavaScript-style inheritance uses of object literals, and the previous fix was not correct either. So we're going back to `this: any` in object literals for now.
24 lines
1,023 B
Plaintext
24 lines
1,023 B
Plaintext
tests/cases/conformance/expressions/thisKeyword/thisInObjectLiterals.ts(7,13): error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type '{ x: this; y: number; }', but here has type '{ x: MyClass; y: number; }'.
|
|
|
|
|
|
==== tests/cases/conformance/expressions/thisKeyword/thisInObjectLiterals.ts (1 errors) ====
|
|
class MyClass {
|
|
t: number;
|
|
|
|
fn() {
|
|
//type of 'this' in an object literal is the containing scope's this
|
|
var t = { x: this, y: this.t };
|
|
var t: { x: MyClass; y: number };
|
|
~
|
|
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type '{ x: this; y: number; }', but here has type '{ x: MyClass; y: number; }'.
|
|
}
|
|
}
|
|
|
|
//type of 'this' in an object literal method is the type of the object literal
|
|
var obj = {
|
|
f() {
|
|
return this.spaaace;
|
|
}
|
|
};
|
|
var obj: { f: () => any; };
|
|
|