Skip to content

Commit 42c0451

Browse files
committed
(x: number | undefined) -> void is subtype of (x?: number | undefined) => void
1 parent 47f26e6 commit 42c0451

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14023,8 +14023,7 @@ namespace ts {
1402314023
}
1402414024

1402514025
const targetCount = getParameterCount(target);
14026-
if (!hasEffectiveRestParameter(target) &&
14027-
(checkMode & SignatureCheckMode.StrictArity ? getParameterCount(source) : getMinArgumentCount(source)) > targetCount) {
14026+
if (!hasEffectiveRestParameter(target) && (checkMode & SignatureCheckMode.StrictArity ? getParameterCount(source) : getMinArgumentCount(source)) > targetCount) {
1402814027
return Ternary.False;
1402914028
}
1403014029

@@ -14084,10 +14083,13 @@ namespace ts {
1408414083
const targetSig = checkMode & SignatureCheckMode.Callback ? undefined : getSingleCallSignature(getNonNullableType(targetType));
1408514084
const callbacks = sourceSig && targetSig && !getTypePredicateOfSignature(sourceSig) && !getTypePredicateOfSignature(targetSig) &&
1408614085
(getFalsyFlags(sourceType) & TypeFlags.Nullable) === (getFalsyFlags(targetType) & TypeFlags.Nullable);
14087-
const related = callbacks ?
14088-
// TODO: GH#18217 It will work if they're both `undefined`, but not if only one is
14086+
let related = callbacks ?
1408914087
compareSignaturesRelated(targetSig!, sourceSig!, (checkMode & SignatureCheckMode.StrictArity) | (strictVariance ? SignatureCheckMode.StrictCallback : SignatureCheckMode.BivariantCallback), reportErrors, errorReporter, incompatibleErrorReporter, compareTypes, reportUnreliableMarkers) :
1409014088
!(checkMode & SignatureCheckMode.Callback) && !strictVariance && compareTypes(sourceType, targetType, /*reportErrors*/ false) || compareTypes(targetType, sourceType, reportErrors);
14089+
// With strict arity, (x: number | undefined) => void is a subtype of (x?: number | undefined) => void
14090+
if (related && checkMode & SignatureCheckMode.StrictArity && i >= getMinArgumentCount(source) && i < getMinArgumentCount(target) && isTypeIdenticalTo(sourceType, targetType)) {
14091+
related = Ternary.False;
14092+
}
1409114093
if (!related) {
1409214094
if (reportErrors) {
1409314095
errorReporter!(Diagnostics.Types_of_parameters_0_and_1_are_incompatible,

0 commit comments

Comments
 (0)