Try to pick a good signature, if no signature matches

This commit is contained in:
Mohamed Hegazy
2014-10-08 15:47:30 -07:00
parent 98f8ec5d5a
commit a8a1fa27d8
3 changed files with 29 additions and 2 deletions
+16 -1
View File
@@ -4508,8 +4508,23 @@ module ts {
}
else {
error(node, Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
return resolveErrorCall(node);
}
// No signature was applicable. We have already reported the errors for the invalid signature.
// If this is a type resolution session, e.g. Language Service, try to get better information that anySignature.
// Pick the first candidate that matches the arity. This way we can get a contextual type for cases like:
// declare function f(a: { xa: number; xb: number; });
// f({ |
if (!fullTypeCheck) {
if (candidates.length) {
for (var i = 0; i < candidates.length; i++) {
if (signatureHasCorrectArity(node, candidates[i])) {
return candidates[i];
}
}
}
}
return resolveErrorCall(node);
// The candidate list orders groups in reverse, but within a group signatures are kept in declaration order
+2 -1
View File
@@ -1204,7 +1204,8 @@ module ts {
}
public static toString(parts: SymbolDisplayPart[]) {
return parts.map(p => p.text).join("");
var result = map(parts, p => p.text);
return result ? result.join("") : "";
}
}
@@ -0,0 +1,11 @@
/// <reference path='fourslash.ts'/>
////function f(a: { xa: number; xb: number; }) { }
////var xc;
////f({
//// /**/
goTo.marker()
verify.memberListContains('xa');
verify.memberListContains('xb');
verify.memberListCount(2);