Skip to content

Commit a8a1fa2

Browse files
committed
Try to pick a good signature, if no signature matches
1 parent 98f8ec5 commit a8a1fa2

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4508,8 +4508,23 @@ module ts {
45084508
}
45094509
else {
45104510
error(node, Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
4511-
return resolveErrorCall(node);
45124511
}
4512+
4513+
// No signature was applicable. We have already reported the errors for the invalid signature.
4514+
// If this is a type resolution session, e.g. Language Service, try to get better information that anySignature.
4515+
// Pick the first candidate that matches the arity. This way we can get a contextual type for cases like:
4516+
// declare function f(a: { xa: number; xb: number; });
4517+
// f({ |
4518+
if (!fullTypeCheck) {
4519+
if (candidates.length) {
4520+
for (var i = 0; i < candidates.length; i++) {
4521+
if (signatureHasCorrectArity(node, candidates[i])) {
4522+
return candidates[i];
4523+
}
4524+
}
4525+
}
4526+
}
4527+
45134528
return resolveErrorCall(node);
45144529

45154530
// The candidate list orders groups in reverse, but within a group signatures are kept in declaration order

src/compiler/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,8 @@ module ts {
12041204
}
12051205

12061206
public static toString(parts: SymbolDisplayPart[]) {
1207-
return parts.map(p => p.text).join("");
1207+
var result = map(parts, p => p.text);
1208+
return result ? result.join("") : "";
12081209
}
12091210
}
12101211

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////function f(a: { xa: number; xb: number; }) { }
4+
////var xc;
5+
////f({
6+
//// /**/
7+
8+
goTo.marker()
9+
verify.memberListContains('xa');
10+
verify.memberListContains('xb');
11+
verify.memberListCount(2);

0 commit comments

Comments
 (0)