diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 272dbb12b97..9a2a6e1f8e7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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); } diff --git a/tests/baselines/reference/noImplicitThisFunctions.errors.txt b/tests/baselines/reference/noImplicitThisFunctions.errors.txt index b00949d5086..f1742bc758a 100644 --- a/tests/baselines/reference/noImplicitThisFunctions.errors.txt +++ b/tests/baselines/reference/noImplicitThisFunctions.errors.txt @@ -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. \ No newline at end of file diff --git a/tests/baselines/reference/noImplicitThisFunctions.js b/tests/baselines/reference/noImplicitThisFunctions.js index e256df2d77f..80ceccbe751 100644 --- a/tests/baselines/reference/noImplicitThisFunctions.js +++ b/tests/baselines/reference/noImplicitThisFunctions.js @@ -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; }; diff --git a/tests/cases/compiler/noImplicitThisFunctions.ts b/tests/cases/compiler/noImplicitThisFunctions.ts index 1e0aa0c4da0..45f0e5a1eb9 100644 --- a/tests/cases/compiler/noImplicitThisFunctions.ts +++ b/tests/cases/compiler/noImplicitThisFunctions.ts @@ -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;