TypeScript Version: TS@next, TS@2.7
not in TS@2.6
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:
http://www.typescriptlang.org/play/#src=type%20Prop%3CT%3E%20%3D%20%7B%20()%3A%20T%20%7D%0A%0Adeclare%20function%20test%3CT%3E(a%3A%20Prop%3CT%3E)%3A%20T%0Adeclare%20function%20test(a%3A%20Prop%3Cany%3E)%3A%20%7B%7D%20%2F%2F%20toggle%20this%20line%0A%0Avar%20a%20%3D%20test(Array)%0A%0Aa.push
Related Issues:
More info:
This is a reduced version of vuejs/vue#7640. The code used to compile in TS 2.6.
TypeScript Version: TS@next, TS@2.7
not in TS@2.6
Search Terms: overload / overloading
Code
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
ArraytoStringbelies the problem.Playground Link:
http://www.typescriptlang.org/play/#src=type%20Prop%3CT%3E%20%3D%20%7B%20()%3A%20T%20%7D%0A%0Adeclare%20function%20test%3CT%3E(a%3A%20Prop%3CT%3E)%3A%20T%0Adeclare%20function%20test(a%3A%20Prop%3Cany%3E)%3A%20%7B%7D%20%2F%2F%20toggle%20this%20line%0A%0Avar%20a%20%3D%20test(Array)%0A%0Aa.push
Related Issues:
More info:
This is a reduced version of vuejs/vue#7640. The code used to compile in TS 2.6.