-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixedFix AvailableA PR has been opened for this issueA PR has been opened for this issue
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
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixedFix AvailableA PR has been opened for this issueA PR has been opened for this issue