You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ node built/local/tsc.js --noEmit --lib es6 --strictNullChecks --noImplicitAny index.ts
index.ts(6,1): error TS2453: The type argument for type parameter 'a' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'.
This is, unfortunately, how TypeScript is intended to treat overloads during type inference. Type inference is not smart enough to infer an overloaded call signature, so it just chooses the last one. If you reverse the order of declarations, you will see that the error switches to the other call.
Adapted from the spec, section 3.10.6 (Type Inference):
When comparing call signatures, signatures in S correspond to signatures in T pairwise in declaration order. If S and T have different numbers of signatures, the excess first signatures in declaration order of the longer list are ignored.
In the example code, S is { (data: number): number; (data: string) => string } and T is { (a: a) => b }. That means that type inference always returns a=string, b = string.
Activity
mhegazy commentedon Aug 31, 2016
Nathan Shively-Sanders (@sandersn) can you take a look
falsandtru commentedon Oct 1, 2016
any updates?
sandersn commentedon Oct 3, 2016
No, I haven't had a chance to look at this yet.
sandersn commentedon Oct 13, 2016
This is, unfortunately, how TypeScript is intended to treat overloads during type inference. Type inference is not smart enough to infer an overloaded call signature, so it just chooses the last one. If you reverse the order of declarations, you will see that the error switches to the other call.
Adapted from the spec, section 3.10.6 (Type Inference):
In the example code, S is
{ (data: number): number; (data: string) => string }and T is{ (a: a) => b }. That means that type inference always returnsa=string, b = string.falsandtru commentedon Oct 13, 2016
I see, thx!