Closed
Description
TypeScript Version: 2.1.0-dev.20160910
Code
declare function foo(cb: (this: number, arg: string) => void): void;
foo(function (): void { this.length; }); // (1)
foo(function (arg: string): void { this.length; }); // (2)
tsc -t es5 ./foo.ts
Expected behavior:
Both (1) and (2) should complain about length
not existing on number
Actual behavior:
(1) correctly complains: foo.ts(3,30): error TS2339: Property 'length' does not exist on type 'number'.
But there is no error for (2).
Adding --noImplicitAny
doesn't change the result.
Adding --noImplicitThis
gives foo.ts(4,36): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
which confirms that this
in (2) is getting inferred as any