Unify signatures in signaturesRelatedTo

This commit is contained in:
Anders Hejlsberg
2022-03-02 13:25:13 -08:00
parent f82d0cb329
commit b615109b61
+9 -4
View File
@@ -13049,7 +13049,7 @@ namespace ts {
return undefined;
}
function getSignatureInstantiation(signature: Signature, typeArguments: Type[] | undefined, isJavascript: boolean, inferredTypeParameters?: readonly TypeParameter[]): Signature {
function getSignatureInstantiation(signature: Signature, typeArguments: readonly Type[] | undefined, isJavascript: boolean, inferredTypeParameters?: readonly TypeParameter[]): Signature {
const instantiatedSignature = getSignatureInstantiationWithoutFillingInTypeArguments(signature, fillMissingTypeArguments(typeArguments, signature.typeParameters, getMinTypeArgumentCount(signature.typeParameters), isJavascript));
if (inferredTypeParameters) {
const returnSignature = getSingleCallOrConstructSignature(getReturnTypeOfSignature(instantiatedSignature));
@@ -20100,10 +20100,15 @@ namespace ts {
sourceObjectFlags & ObjectFlags.Reference && targetObjectFlags & ObjectFlags.Reference && (source as TypeReference).target === (target as TypeReference).target) {
// We have instantiations of the same anonymous type (which typically will be the type of a
// method). Simply do a pairwise comparison of the signatures in the two signature lists instead
// of the much more expensive N * M comparison matrix we explore below. We erase type parameters
// as they are known to always be the same.
// of the much more expensive N * M comparison matrix we explore below. We instantiate the source
// signature with the type parameters of the target signature to unify the two.
for (let i = 0; i < targetSignatures.length; i++) {
const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], /*erase*/ true, reportErrors, incompatibleReporter(sourceSignatures[i], targetSignatures[i]));
const sourceSignature = sourceSignatures[i];
const targetSignature = targetSignatures[i];
const instantiatedSourceSignature = targetSignature.typeParameters ?
getSignatureInstantiation(sourceSignature, targetSignature.typeParameters, isInJSFile(sourceSignature.declaration)) :
sourceSignature;
const related = signatureRelatedTo(instantiatedSourceSignature, targetSignature, /*erase*/ false, reportErrors, incompatibleReporter(instantiatedSourceSignature, targetSignature));
if (!related) {
return Ternary.False;
}