@@ -4115,6 +4115,16 @@ namespace ts {
4115
4115
return signature.erasedSignatureCache;
4116
4116
}
4117
4117
4118
+ function getAnyReturningErasedSignature(signature: Signature): Signature {
4119
+ if (!signature.anyReturningErasedSignatureCache) {
4120
+ const erasedSignature = getErasedSignature(signature);
4121
+ const anyReturningErasedSignature = cloneSignature(erasedSignature);
4122
+ anyReturningErasedSignature.resolvedReturnType = anyType;
4123
+ signature.anyReturningErasedSignatureCache = anyReturningErasedSignature;
4124
+ }
4125
+ return signature.anyReturningErasedSignatureCache;
4126
+ }
4127
+
4118
4128
function getOrCreateTypeFromSignature(signature: Signature): ObjectType {
4119
4129
// There are two ways to declare a construct signature, one is by declaring a class constructor
4120
4130
// using the constructor keyword, and the other is declaring a bare construct signature in an
@@ -4985,16 +4995,19 @@ namespace ts {
4985
4995
const erasedSource = getErasedSignature(implementation);
4986
4996
const erasedTarget = getErasedSignature(overload);
4987
4997
4998
+ // First see if the return types are compatible in either direction.
4988
4999
const sourceReturnType = getReturnTypeOfSignature(erasedSource);
4989
5000
const targetReturnType = getReturnTypeOfSignature(erasedTarget);
4990
5001
if (targetReturnType === voidType
4991
5002
|| checkTypeRelatedTo(targetReturnType, sourceReturnType, assignableRelation, /*errorNode*/ undefined)
4992
5003
|| checkTypeRelatedTo(sourceReturnType, targetReturnType, assignableRelation, /*errorNode*/ undefined)) {
4993
- const anyReturningSource = cloneSignature(erasedSource);
4994
- const anyReturningTarget = cloneSignature(erasedTarget);
4995
- anyReturningSource.resolvedReturnType = anyType;
4996
- anyReturningTarget.resolvedReturnType = anyType;
4997
5004
5005
+ // The return types are compatible, so create versions of the signature with 'any' as the return type.
5006
+ // We need to do this so that we can check assignability while disregarding the return type.
5007
+ const anyReturningSource = getAnyReturningErasedSignature(implementation);
5008
+ const anyReturningTarget = getAnyReturningErasedSignature(overload);
5009
+
5010
+ // Create object types to actually perform relation checks.
4998
5011
const anyReturningSourceType = getOrCreateTypeFromSignature(anyReturningSource);
4999
5012
const anyReturningTargetType = getOrCreateTypeFromSignature(anyReturningTarget);
5000
5013
return checkTypeRelatedTo(anyReturningSourceType, anyReturningTargetType, assignableRelation, /*errorNode*/ undefined);
0 commit comments