@@ -8177,8 +8177,7 @@ namespace ts {
81778177 function isSignatureAssignableTo(source: Signature,
81788178 target: Signature,
81798179 ignoreReturnTypes: boolean): boolean {
8180- return compareSignaturesRelated(source, target, /*checkAsCallback*/ false, ignoreReturnTypes, /*reportErrors*/ false,
8181- /*errorReporter*/ undefined, compareTypesAssignable) !== Ternary.False;
8180+ return compareSignaturesRelated(source, target, ignoreReturnTypes, /*reportErrors*/ false, /*errorReporter*/ undefined, compareTypesAssignable) !== Ternary.False;
81828181 }
81838182
81848183 type ErrorReporter = (message: DiagnosticMessage, arg0?: string, arg1?: string) => void;
@@ -8188,7 +8187,6 @@ namespace ts {
81888187 */
81898188 function compareSignaturesRelated(source: Signature,
81908189 target: Signature,
8191- checkAsCallback: boolean,
81928190 ignoreReturnTypes: boolean,
81938191 reportErrors: boolean,
81948192 errorReporter: ErrorReporter,
@@ -8231,23 +8229,9 @@ namespace ts {
82318229 const sourceParams = source.parameters;
82328230 const targetParams = target.parameters;
82338231 for (let i = 0; i < checkCount; i++) {
8234- const sourceType = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source);
8235- const targetType = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target);
8236- const sourceSig = getSingleCallSignature(getNonNullableType(sourceType));
8237- const targetSig = getSingleCallSignature(getNonNullableType(targetType));
8238- // In order to ensure that any generic type Foo<T> is at least co-variant with respect to T no matter
8239- // how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions,
8240- // they naturally relate only contra-variantly). However, if the source and target parameters both have
8241- // function types with a single call signature, we known we are relating two callback parameters. In
8242- // that case it is sufficient to only relate the parameters of the signatures co-variantly because,
8243- // similar to return values, callback parameters are output positions. This means that a Promise<T>,
8244- // where T is used only in callback parameter positions, will be co-variant (as opposed to bi-variant)
8245- // with respect to T.
8246- const callbacks = sourceSig && targetSig && !sourceSig.typePredicate && !targetSig.typePredicate &&
8247- (getFalsyFlags(sourceType) & TypeFlags.Nullable) === (getFalsyFlags(targetType) & TypeFlags.Nullable);
8248- const related = callbacks ?
8249- compareSignaturesRelated(targetSig, sourceSig, /*checkAsCallback*/ true, /*ignoreReturnTypes*/ false, reportErrors, errorReporter, compareTypes) :
8250- !checkAsCallback && compareTypes(sourceType, targetType, /*reportErrors*/ false) || compareTypes(targetType, sourceType, reportErrors);
8232+ const s = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source);
8233+ const t = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target);
8234+ const related = compareTypes(s, t, /*reportErrors*/ false) || compareTypes(t, s, reportErrors);
82518235 if (!related) {
82528236 if (reportErrors) {
82538237 errorReporter(Diagnostics.Types_of_parameters_0_and_1_are_incompatible,
@@ -8279,11 +8263,7 @@ namespace ts {
82798263 }
82808264 }
82818265 else {
8282- // When relating callback signatures, we still need to relate return types bi-variantly as otherwise
8283- // the containing type wouldn't be co-variant. For example, interface Foo<T> { add(cb: () => T): void }
8284- // wouldn't be co-variant for T without this rule.
8285- result &= checkAsCallback && compareTypes(targetReturnType, sourceReturnType, /*reportErrors*/ false) ||
8286- compareTypes(sourceReturnType, targetReturnType, reportErrors);
8266+ result &= compareTypes(sourceReturnType, targetReturnType, reportErrors);
82878267 }
82888268
82898269 }
@@ -9251,7 +9231,7 @@ namespace ts {
92519231 * See signatureAssignableTo, compareSignaturesIdentical
92529232 */
92539233 function signatureRelatedTo(source: Signature, target: Signature, reportErrors: boolean): Ternary {
9254- return compareSignaturesRelated(source, target, /*checkAsCallback*/ false, /* ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo);
9234+ return compareSignaturesRelated(source, target, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo);
92559235 }
92569236
92579237 function signaturesIdenticalTo(source: Type, target: Type, kind: SignatureKind): Ternary {
0 commit comments