@@ -20138,7 +20138,7 @@ namespace ts {
20138
20138
const paramType = getTypeAtPosition(signature, i);
20139
20139
// For context sensitive arguments we pass the identityMapper, which is a signal to treat all
20140
20140
// context sensitive function expressions as wildcards
20141
- const checkMode = (excludeArgument && excludeArgument[i] ? CheckMode.SkipContextSensitive : 0) |
20141
+ const checkMode = (excludeArgument && i < excludeArgument.length && excludeArgument[i] ? CheckMode.SkipContextSensitive : 0) |
20142
20142
(excludeArgument ? CheckMode.SkipGenericFunctions : 0);
20143
20143
const argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
20144
20144
inferTypes(context.inferences, argType, paramType);
@@ -20241,7 +20241,7 @@ namespace ts {
20241
20241
// However "context" and "updater" are implicit and can't be specify by users. Only the first parameter, props,
20242
20242
// can be specified by users through attributes property.
20243
20243
const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
20244
- const checkMode = excludeArgument && excludeArgument[0] ? CheckMode.SkipContextSensitive : 0;
20244
+ const checkMode = excludeArgument && excludeArgument.length > 0 && excludeArgument [0] ? CheckMode.SkipContextSensitive : 0;
20245
20245
const attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*contextualMapper*/ undefined, checkMode);
20246
20246
return checkTypeRelatedToAndOptionallyElaborate(attributesType, paramType, relation, reportErrors ? node.tagName : undefined, node.attributes);
20247
20247
}
@@ -20276,13 +20276,13 @@ namespace ts {
20276
20276
const arg = args[i];
20277
20277
if (arg.kind !== SyntaxKind.OmittedExpression) {
20278
20278
const paramType = getTypeAtPosition(signature, i);
20279
- const checkMode = (excludeArgument && excludeArgument[i] ? CheckMode.SkipContextSensitive : 0) |
20279
+ const checkMode = (excludeArgument && i < excludeArgument.length && excludeArgument[i] ? CheckMode.SkipContextSensitive : 0) |
20280
20280
(excludeArgument ? CheckMode.SkipGenericFunctions : 0);
20281
20281
const argType = checkExpressionWithContextualType(arg, paramType, /*contextualMapper*/ undefined, checkMode);
20282
20282
// If one or more arguments are still excluded (as indicated by a non-null excludeArgument parameter),
20283
20283
// we obtain the regular type of any object literal arguments because we may not have inferred complete
20284
20284
// parameter types yet and therefore excess property checks may yield false positives (see #17041).
20285
- const checkArgType = excludeArgument ? getRegularTypeOfObjectLiteral(argType) : argType;
20285
+ const checkArgType = excludeArgument && excludeArgument.length ? getRegularTypeOfObjectLiteral(argType) : argType;
20286
20286
if (!checkTypeRelatedToAndOptionallyElaborate(checkArgType, paramType, relation, reportErrors ? arg : undefined, arg, headMessage)) {
20287
20287
return false;
20288
20288
}
@@ -20665,7 +20665,7 @@ namespace ts {
20665
20665
}
20666
20666
else {
20667
20667
inferenceContext = createInferenceContext(candidate.typeParameters, candidate, /*flags*/ isInJSFile(node) ? InferenceFlags.AnyDefault : InferenceFlags.None);
20668
- typeArgumentTypes = inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext);
20668
+ typeArgumentTypes = inferTypeArguments(node, candidate, args, excludeArgument || emptyArray , inferenceContext);
20669
20669
}
20670
20670
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
20671
20671
// If the original signature has a generic rest type, instantiation may produce a
@@ -20678,14 +20678,14 @@ namespace ts {
20678
20678
else {
20679
20679
checkCandidate = candidate;
20680
20680
}
20681
- if (!checkApplicableSignature(node, args, checkCandidate, relation, excludeArgument, /*reportErrors*/ false)) {
20681
+ if (!checkApplicableSignature(node, args, checkCandidate, relation, excludeArgument || inferenceContext && emptyArray , /*reportErrors*/ false)) {
20682
20682
// Give preference to error candidates that have no rest parameters (as they are more specific)
20683
20683
if (!candidateForArgumentError || getEffectiveRestType(candidateForArgumentError) || !getEffectiveRestType(checkCandidate)) {
20684
20684
candidateForArgumentError = checkCandidate;
20685
20685
}
20686
20686
continue;
20687
20687
}
20688
- if (excludeArgument) {
20688
+ if (excludeArgument || inferenceContext && inferenceContext.flags & InferenceFlags.SkippedGenericFunction ) {
20689
20689
// If one or more context sensitive arguments were excluded, we start including
20690
20690
// them now (and keeping do so for any subsequent candidates) and perform a second
20691
20691
// round of type inference and applicability checking for this particular candidate.
@@ -20830,7 +20830,7 @@ namespace ts {
20830
20830
20831
20831
function inferSignatureInstantiationForOverloadFailure(node: CallLikeExpression, typeParameters: ReadonlyArray<TypeParameter>, candidate: Signature, args: ReadonlyArray<Expression>): Signature {
20832
20832
const inferenceContext = createInferenceContext(typeParameters, candidate, /*flags*/ isInJSFile(node) ? InferenceFlags.AnyDefault : InferenceFlags.None);
20833
- const typeArgumentTypes = inferTypeArguments(node, candidate, args, getExcludeArgument(args), inferenceContext);
20833
+ const typeArgumentTypes = inferTypeArguments(node, candidate, args, getExcludeArgument(args) || emptyArray , inferenceContext);
20834
20834
return createSignatureInstantiation(candidate, typeArgumentTypes);
20835
20835
}
20836
20836
@@ -20932,6 +20932,7 @@ namespace ts {
20932
20932
// sensitive arguments are being deferred) and every call signature is generic and returns a function type,
20933
20933
// we return resolvingSignature here. This result will be propagated out and turned into anyFunctionType.
20934
20934
if (checkMode & CheckMode.SkipGenericFunctions && callSignatures.every(isGenericFunctionReturningFunction)) {
20935
+ skippedGenericFunction(node, checkMode);
20935
20936
return resolvingSignature;
20936
20937
}
20937
20938
// If the function is explicitly marked with `@class`, then it must be constructed.
@@ -23387,6 +23388,7 @@ namespace ts {
23387
23388
const signature = getSingleCallSignature(type);
23388
23389
if (signature && signature.typeParameters) {
23389
23390
if (checkMode & CheckMode.SkipGenericFunctions) {
23391
+ skippedGenericFunction(node, checkMode);
23390
23392
return anyFunctionType;
23391
23393
}
23392
23394
const contextualType = getApparentTypeOfContextualType(<Expression>node);
@@ -23429,6 +23431,15 @@ namespace ts {
23429
23431
return type;
23430
23432
}
23431
23433
23434
+ function skippedGenericFunction(node: Node, checkMode: CheckMode) {
23435
+ if (checkMode & CheckMode.Inferential) {
23436
+ // We have skipped a generic function during inferential typing. Obtain the inference context and
23437
+ // indicate this has occurred such that we know a second pass of inference is be needed.
23438
+ const context = <InferenceContext>getContextualMapper(node);
23439
+ context.flags |= InferenceFlags.SkippedGenericFunction;
23440
+ }
23441
+ }
23442
+
23432
23443
function hasInferenceCandidates(info: InferenceInfo) {
23433
23444
return !!(info.candidates || info.contraCandidates);
23434
23445
}
0 commit comments