Error on all uses of this that are implicitly any

Previously it was only an error inside an function.
This commit is contained in:
Nathan Shively-Sanders
2016-03-30 13:31:10 -07:00
parent f64110aa0f
commit 0113ad5250
4 changed files with 9 additions and 6 deletions
+1 -1
View File
@@ -8110,7 +8110,7 @@ namespace ts {
}
}
if (compilerOptions.noImplicitThis && isFunctionLike(container)) {
if (compilerOptions.noImplicitThis) {
// With noImplicitThis, functions may not reference 'this' if it has type 'any'
error(node, Diagnostics.this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation);
}
@@ -1,7 +1,8 @@
tests/cases/compiler/noImplicitThisFunctions.ts(14,12): error TS2681: 'this' implicitly has type 'any' because it does not have a type annotation.
tests/cases/compiler/noImplicitThisFunctions.ts(18,38): error TS2681: 'this' implicitly has type 'any' because it does not have a type annotation.
==== tests/cases/compiler/noImplicitThisFunctions.ts (1 errors) ====
==== tests/cases/compiler/noImplicitThisFunctions.ts (2 errors) ====
function f1(x) {
// implicit any is still allowed
@@ -20,6 +21,8 @@ tests/cases/compiler/noImplicitThisFunctions.ts(14,12): error TS2681: 'this' imp
!!! error TS2681: 'this' implicitly has type 'any' because it does not have a type annotation.
}
// ok, arrow functions don't even bind `this`, so `this` is just `window`
// error: `this` is `window`, but is still of type `any`
let f4: (b: number) => number = b => this.c + b;
~~~~
!!! error TS2681: 'this' implicitly has type 'any' because it does not have a type annotation.
@@ -15,7 +15,7 @@ function f3(z: number): number {
return this.a + z;
}
// ok, arrow functions don't even bind `this`, so `this` is just `window`
// error: `this` is `window`, but is still of type `any`
let f4: (b: number) => number = b => this.c + b;
@@ -33,5 +33,5 @@ function f3(z) {
// error: this is implicitly any
return this.a + z;
}
// ok, arrow functions don't even bind `this`, so `this` is just `window`
// error: `this` is `window`, but is still of type `any`
var f4 = function (b) { return _this.c + b; };
@@ -15,5 +15,5 @@ function f3(z: number): number {
return this.a + z;
}
// ok, arrow functions don't even bind `this`, so `this` is just `window`
// error: `this` is `window`, but is still of type `any`
let f4: (b: number) => number = b => this.c + b;