mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
(x: number | undefined) -> void is subtype of (x?: number | undefined) => void
This commit is contained in:
@@ -14023,8 +14023,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
const targetCount = getParameterCount(target);
|
||||
if (!hasEffectiveRestParameter(target) &&
|
||||
(checkMode & SignatureCheckMode.StrictArity ? getParameterCount(source) : getMinArgumentCount(source)) > targetCount) {
|
||||
if (!hasEffectiveRestParameter(target) && (checkMode & SignatureCheckMode.StrictArity ? getParameterCount(source) : getMinArgumentCount(source)) > targetCount) {
|
||||
return Ternary.False;
|
||||
}
|
||||
|
||||
@@ -14084,10 +14083,13 @@ namespace ts {
|
||||
const targetSig = checkMode & SignatureCheckMode.Callback ? undefined : getSingleCallSignature(getNonNullableType(targetType));
|
||||
const callbacks = sourceSig && targetSig && !getTypePredicateOfSignature(sourceSig) && !getTypePredicateOfSignature(targetSig) &&
|
||||
(getFalsyFlags(sourceType) & TypeFlags.Nullable) === (getFalsyFlags(targetType) & TypeFlags.Nullable);
|
||||
const related = callbacks ?
|
||||
// TODO: GH#18217 It will work if they're both `undefined`, but not if only one is
|
||||
let related = callbacks ?
|
||||
compareSignaturesRelated(targetSig!, sourceSig!, (checkMode & SignatureCheckMode.StrictArity) | (strictVariance ? SignatureCheckMode.StrictCallback : SignatureCheckMode.BivariantCallback), reportErrors, errorReporter, incompatibleErrorReporter, compareTypes, reportUnreliableMarkers) :
|
||||
!(checkMode & SignatureCheckMode.Callback) && !strictVariance && compareTypes(sourceType, targetType, /*reportErrors*/ false) || compareTypes(targetType, sourceType, reportErrors);
|
||||
// With strict arity, (x: number | undefined) => void is a subtype of (x?: number | undefined) => void
|
||||
if (related && checkMode & SignatureCheckMode.StrictArity && i >= getMinArgumentCount(source) && i < getMinArgumentCount(target) && isTypeIdenticalTo(sourceType, targetType)) {
|
||||
related = Ternary.False;
|
||||
}
|
||||
if (!related) {
|
||||
if (reportErrors) {
|
||||
errorReporter!(Diagnostics.Types_of_parameters_0_and_1_are_incompatible,
|
||||
|
||||
Reference in New Issue
Block a user