@@ -16156,36 +16156,38 @@ namespace ts {
16156
16156
const restIndex = sourceRestType || targetRestType ? paramCount - 1 : -1;
16157
16157
16158
16158
for (let i = 0; i < paramCount; i++) {
16159
- const sourceType = i === restIndex ? getRestTypeAtPosition(source, i) : getTypeAtPosition(source, i);
16160
- const targetType = i === restIndex ? getRestTypeAtPosition(target, i) : getTypeAtPosition(target, i);
16161
- // In order to ensure that any generic type Foo<T> is at least co-variant with respect to T no matter
16162
- // how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions,
16163
- // they naturally relate only contra-variantly). However, if the source and target parameters both have
16164
- // function types with a single call signature, we know we are relating two callback parameters. In
16165
- // that case it is sufficient to only relate the parameters of the signatures co-variantly because,
16166
- // similar to return values, callback parameters are output positions. This means that a Promise<T>,
16167
- // where T is used only in callback parameter positions, will be co-variant (as opposed to bi-variant)
16168
- // with respect to T.
16169
- const sourceSig = checkMode & SignatureCheckMode.Callback ? undefined : getSingleCallSignature(getNonNullableType(sourceType));
16170
- const targetSig = checkMode & SignatureCheckMode.Callback ? undefined : getSingleCallSignature(getNonNullableType(targetType));
16171
- const callbacks = sourceSig && targetSig && !getTypePredicateOfSignature(sourceSig) && !getTypePredicateOfSignature(targetSig) &&
16172
- (getFalsyFlags(sourceType) & TypeFlags.Nullable) === (getFalsyFlags(targetType) & TypeFlags.Nullable);
16173
- let related = callbacks ?
16174
- compareSignaturesRelated(targetSig!, sourceSig!, (checkMode & SignatureCheckMode.StrictArity) | (strictVariance ? SignatureCheckMode.StrictCallback : SignatureCheckMode.BivariantCallback), reportErrors, errorReporter, incompatibleErrorReporter, compareTypes, reportUnreliableMarkers) :
16175
- !(checkMode & SignatureCheckMode.Callback) && !strictVariance && compareTypes(sourceType, targetType, /*reportErrors*/ false) || compareTypes(targetType, sourceType, reportErrors);
16176
- // With strict arity, (x: number | undefined) => void is a subtype of (x?: number | undefined) => void
16177
- if (related && checkMode & SignatureCheckMode.StrictArity && i >= getMinArgumentCount(source) && i < getMinArgumentCount(target) && compareTypes(sourceType, targetType, /*reportErrors*/ false)) {
16178
- related = Ternary.False;
16179
- }
16180
- if (!related) {
16181
- if (reportErrors) {
16182
- errorReporter!(Diagnostics.Types_of_parameters_0_and_1_are_incompatible,
16183
- unescapeLeadingUnderscores(getParameterNameAtPosition(source, i)),
16184
- unescapeLeadingUnderscores(getParameterNameAtPosition(target, i)));
16159
+ const sourceType = i === restIndex ? getRestTypeAtPosition(source, i) : tryGetTypeAtPosition(source, i);
16160
+ const targetType = i === restIndex ? getRestTypeAtPosition(target, i) : tryGetTypeAtPosition(target, i);
16161
+ if (sourceType && targetType) {
16162
+ // In order to ensure that any generic type Foo<T> is at least co-variant with respect to T no matter
16163
+ // how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions,
16164
+ // they naturally relate only contra-variantly). However, if the source and target parameters both have
16165
+ // function types with a single call signature, we know we are relating two callback parameters. In
16166
+ // that case it is sufficient to only relate the parameters of the signatures co-variantly because,
16167
+ // similar to return values, callback parameters are output positions. This means that a Promise<T>,
16168
+ // where T is used only in callback parameter positions, will be co-variant (as opposed to bi-variant)
16169
+ // with respect to T.
16170
+ const sourceSig = checkMode & SignatureCheckMode.Callback ? undefined : getSingleCallSignature(getNonNullableType(sourceType));
16171
+ const targetSig = checkMode & SignatureCheckMode.Callback ? undefined : getSingleCallSignature(getNonNullableType(targetType));
16172
+ const callbacks = sourceSig && targetSig && !getTypePredicateOfSignature(sourceSig) && !getTypePredicateOfSignature(targetSig) &&
16173
+ (getFalsyFlags(sourceType) & TypeFlags.Nullable) === (getFalsyFlags(targetType) & TypeFlags.Nullable);
16174
+ let related = callbacks ?
16175
+ compareSignaturesRelated(targetSig!, sourceSig!, (checkMode & SignatureCheckMode.StrictArity) | (strictVariance ? SignatureCheckMode.StrictCallback : SignatureCheckMode.BivariantCallback), reportErrors, errorReporter, incompatibleErrorReporter, compareTypes, reportUnreliableMarkers) :
16176
+ !(checkMode & SignatureCheckMode.Callback) && !strictVariance && compareTypes(sourceType, targetType, /*reportErrors*/ false) || compareTypes(targetType, sourceType, reportErrors);
16177
+ // With strict arity, (x: number | undefined) => void is a subtype of (x?: number | undefined) => void
16178
+ if (related && checkMode & SignatureCheckMode.StrictArity && i >= getMinArgumentCount(source) && i < getMinArgumentCount(target) && compareTypes(sourceType, targetType, /*reportErrors*/ false)) {
16179
+ related = Ternary.False;
16185
16180
}
16186
- return Ternary.False;
16181
+ if (!related) {
16182
+ if (reportErrors) {
16183
+ errorReporter!(Diagnostics.Types_of_parameters_0_and_1_are_incompatible,
16184
+ unescapeLeadingUnderscores(getParameterNameAtPosition(source, i)),
16185
+ unescapeLeadingUnderscores(getParameterNameAtPosition(target, i)));
16186
+ }
16187
+ return Ternary.False;
16188
+ }
16189
+ result &= related;
16187
16190
}
16188
- result &= related;
16189
16191
}
16190
16192
16191
16193
if (!(checkMode & SignatureCheckMode.IgnoreReturnTypes)) {
0 commit comments