Closed
Description
TypeScript Version: 2.1.4
Code
declare function it(f: () => void): number;
declare function it(f: (x: string) => void): string;
let r = it((x) => {x});
Expected behavior:
The inferred type of x
inside the closure should be string
.
Actual behavior:
The inferred type of x
is any
. Moreover, this triggers noImplicitAny errors.
It appears that the first overload somehow throws off the type inference (no issue without overloads). However, the resulting type of r
is string
thus the second overload was ultimately chosen. Despite that, the type of x
is not inferred to match the one in the overload.
This example worked as expected in TS 2.0.x so it appears to be a regression.
//cc @calebegg