@@ -8177,8 +8177,7 @@ namespace ts {
8177
8177
function isSignatureAssignableTo(source: Signature,
8178
8178
target: Signature,
8179
8179
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;
8182
8181
}
8183
8182
8184
8183
type ErrorReporter = (message: DiagnosticMessage, arg0?: string, arg1?: string) => void;
@@ -8188,7 +8187,6 @@ namespace ts {
8188
8187
*/
8189
8188
function compareSignaturesRelated(source: Signature,
8190
8189
target: Signature,
8191
- checkAsCallback: boolean,
8192
8190
ignoreReturnTypes: boolean,
8193
8191
reportErrors: boolean,
8194
8192
errorReporter: ErrorReporter,
@@ -8231,23 +8229,9 @@ namespace ts {
8231
8229
const sourceParams = source.parameters;
8232
8230
const targetParams = target.parameters;
8233
8231
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);
8251
8235
if (!related) {
8252
8236
if (reportErrors) {
8253
8237
errorReporter(Diagnostics.Types_of_parameters_0_and_1_are_incompatible,
@@ -8279,11 +8263,7 @@ namespace ts {
8279
8263
}
8280
8264
}
8281
8265
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);
8287
8267
}
8288
8268
8289
8269
}
@@ -9251,7 +9231,7 @@ namespace ts {
9251
9231
* See signatureAssignableTo, compareSignaturesIdentical
9252
9232
*/
9253
9233
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);
9255
9235
}
9256
9236
9257
9237
function signaturesIdenticalTo(source: Type, target: Type, kind: SignatureKind): Ternary {
0 commit comments