File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11395,7 +11395,8 @@ namespace ts {
1139511395 const bestMatchingType =
1139611396 findMatchingDiscriminantType(source, target) ||
1139711397 findMatchingTypeReferenceOrTypeAliasReference(source, target) ||
11398- findBestTypeForObjectLiteral(source, target);
11398+ findBestTypeForObjectLiteral(source, target) ||
11399+ findBestTypeForInvokable(source, target);
1139911400
1140011401 isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true);
1140111402 }
@@ -11426,6 +11427,15 @@ namespace ts {
1142611427 }
1142711428 }
1142811429
11430+ function findBestTypeForInvokable(source: Type, unionTarget: UnionOrIntersectionType) {
11431+ let signatureKind = SignatureKind.Call;
11432+ const hasSignatures = getSignaturesOfType(source, signatureKind).length > 0 ||
11433+ (signatureKind = SignatureKind.Construct, getSignaturesOfType(source, signatureKind).length > 0);
11434+ if (hasSignatures) {
11435+ return find(unionTarget.types, t => getSignaturesOfType(t, signatureKind).length > 0);
11436+ }
11437+ }
11438+
1142911439 // Keep this up-to-date with the same logic within `getApparentTypeOfContextualType`, since they should behave similarly
1143011440 function findMatchingDiscriminantType(source: Type, target: UnionOrIntersectionType) {
1143111441 let match: Type | undefined;
You can’t perform that action at this time.
0 commit comments