Closed
Description
TypeScript Version: TS@next, [email protected]
not in [email protected]
Search Terms: overload / overloading
Code
type Prop<T> = { (): T }
declare function test<T>(a: Prop<T>): T
declare function test(a: Prop<any>): {} // toggle this line
var a = test(Array)
a.push
Expected behavior:
Code compiles. Since the first overloading should always match.
Actual behavior:
Code doesn't compile. TSC chooses the second overloading instead of the first one.
Toggling off the second overload signature can make code compile but should not.
Note: changing Array
to String
belies the problem.
Playground Link:
More info:
This is a reduced version of vuejs/vue#7640. The code used to compile in TS 2.6.