@@ -20068,15 +20068,14 @@ namespace ts {
20068
20068
return getSignatureInstantiation(signature, getInferredTypes(context), isInJSFile(contextualSignature.declaration));
20069
20069
}
20070
20070
20071
- function inferJsxTypeArguments(node: JsxOpeningLikeElement, signature: Signature, excludeArgument: ReadonlyArray<boolean> | undefined , context: InferenceContext): Type[] {
20071
+ function inferJsxTypeArguments(node: JsxOpeningLikeElement, signature: Signature, checkMode: CheckMode , context: InferenceContext): Type[] {
20072
20072
const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
20073
- const checkMode = excludeArgument && excludeArgument[0] ? CheckMode.SkipContextSensitive : 0;
20074
20073
const checkAttrType = checkExpressionWithContextualType(node.attributes, paramType, context, checkMode);
20075
20074
inferTypes(context.inferences, checkAttrType, paramType);
20076
20075
return getInferredTypes(context);
20077
20076
}
20078
20077
20079
- function inferTypeArguments(node: CallLikeExpression, signature: Signature, args: ReadonlyArray<Expression>, excludeArgument: ReadonlyArray<boolean> | undefined , context: InferenceContext): Type[] {
20078
+ function inferTypeArguments(node: CallLikeExpression, signature: Signature, args: ReadonlyArray<Expression>, checkMode: CheckMode , context: InferenceContext): Type[] {
20080
20079
// Clear out all the inference results from the last time inferTypeArguments was called on this context
20081
20080
for (const inference of context.inferences) {
20082
20081
// As an optimization, we don't have to clear (and later recompute) inferred types
@@ -20089,7 +20088,7 @@ namespace ts {
20089
20088
}
20090
20089
20091
20090
if (isJsxOpeningLikeElement(node)) {
20092
- return inferJsxTypeArguments(node, signature, excludeArgument , context);
20091
+ return inferJsxTypeArguments(node, signature, checkMode , context);
20093
20092
}
20094
20093
20095
20094
// If a contextual type is available, infer from that type to the return type of the call expression. For
@@ -20136,10 +20135,6 @@ namespace ts {
20136
20135
const arg = args[i];
20137
20136
if (arg.kind !== SyntaxKind.OmittedExpression) {
20138
20137
const paramType = getTypeAtPosition(signature, i);
20139
- // For context sensitive arguments we pass the identityMapper, which is a signal to treat all
20140
- // context sensitive function expressions as wildcards
20141
- const checkMode = (excludeArgument && i < excludeArgument.length && excludeArgument[i] ? CheckMode.SkipContextSensitive : 0) |
20142
- (excludeArgument ? CheckMode.SkipGenericFunctions : 0);
20143
20138
const argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
20144
20139
inferTypes(context.inferences, argType, paramType);
20145
20140
}
@@ -20234,14 +20229,12 @@ namespace ts {
20234
20229
* @param node a JSX opening-like element we are trying to figure its call signature
20235
20230
* @param signature a candidate signature we are trying whether it is a call signature
20236
20231
* @param relation a relationship to check parameter and argument type
20237
- * @param excludeArgument
20238
20232
*/
20239
- function checkApplicableSignatureForJsxOpeningLikeElement(node: JsxOpeningLikeElement, signature: Signature, relation: Map<RelationComparisonResult>, excludeArgument: boolean[] | undefined , reportErrors: boolean) {
20233
+ function checkApplicableSignatureForJsxOpeningLikeElement(node: JsxOpeningLikeElement, signature: Signature, relation: Map<RelationComparisonResult>, checkMode: CheckMode , reportErrors: boolean) {
20240
20234
// Stateless function components can have maximum of three arguments: "props", "context", and "updater".
20241
20235
// However "context" and "updater" are implicit and can't be specify by users. Only the first parameter, props,
20242
20236
// can be specified by users through attributes property.
20243
20237
const paramType = getEffectiveFirstArgumentForJsxSignature(signature, node);
20244
- const checkMode = excludeArgument && excludeArgument.length > 0 && excludeArgument[0] ? CheckMode.SkipContextSensitive : 0;
20245
20238
const attributesType = checkExpressionWithContextualType(node.attributes, paramType, /*contextualMapper*/ undefined, checkMode);
20246
20239
return checkTypeRelatedToAndOptionallyElaborate(attributesType, paramType, relation, reportErrors ? node.tagName : undefined, node.attributes);
20247
20240
}
@@ -20251,10 +20244,10 @@ namespace ts {
20251
20244
args: ReadonlyArray<Expression>,
20252
20245
signature: Signature,
20253
20246
relation: Map<RelationComparisonResult>,
20254
- excludeArgument: boolean[] | undefined ,
20247
+ checkMode: CheckMode ,
20255
20248
reportErrors: boolean) {
20256
20249
if (isJsxOpeningLikeElement(node)) {
20257
- return checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, excludeArgument , reportErrors);
20250
+ return checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, checkMode , reportErrors);
20258
20251
}
20259
20252
const thisType = getThisTypeOfSignature(signature);
20260
20253
if (thisType && thisType !== voidType && node.kind !== SyntaxKind.NewExpression) {
@@ -20276,13 +20269,11 @@ namespace ts {
20276
20269
const arg = args[i];
20277
20270
if (arg.kind !== SyntaxKind.OmittedExpression) {
20278
20271
const paramType = getTypeAtPosition(signature, i);
20279
- const checkMode = (excludeArgument && i < excludeArgument.length && excludeArgument[i] ? CheckMode.SkipContextSensitive : 0) |
20280
- (excludeArgument ? CheckMode.SkipGenericFunctions : 0);
20281
20272
const argType = checkExpressionWithContextualType(arg, paramType, /*contextualMapper*/ undefined, checkMode);
20282
- // If one or more arguments are still excluded (as indicated by a non-null excludeArgument parameter ),
20273
+ // If one or more arguments are still excluded (as indicated by CheckMode.SkipContextSensitive ),
20283
20274
// we obtain the regular type of any object literal arguments because we may not have inferred complete
20284
20275
// parameter types yet and therefore excess property checks may yield false positives (see #17041).
20285
- const checkArgType = excludeArgument && excludeArgument.length ? getRegularTypeOfObjectLiteral(argType) : argType;
20276
+ const checkArgType = checkMode & CheckMode.SkipContextSensitive ? getRegularTypeOfObjectLiteral(argType) : argType;
20286
20277
if (!checkTypeRelatedToAndOptionallyElaborate(checkArgType, paramType, relation, reportErrors ? arg : undefined, arg, headMessage)) {
20287
20278
return false;
20288
20279
}
@@ -20540,7 +20531,7 @@ namespace ts {
20540
20531
// For a decorator, no arguments are susceptible to contextual typing due to the fact
20541
20532
// decorators are applied to a declaration by the emitter, and not to an expression.
20542
20533
const isSingleNonGenericCandidate = candidates.length === 1 && !candidates[0].typeParameters;
20543
- let excludeArgument = !isDecorator && !isSingleNonGenericCandidate ? getExcludeArgument (args) : undefined ;
20534
+ let argCheckMode = !isDecorator && !isSingleNonGenericCandidate && some (args, isContextSensitive) ? CheckMode.SkipContextSensitive : CheckMode.Normal ;
20544
20535
20545
20536
// The following variables are captured and modified by calls to chooseOverload.
20546
20537
// If overload resolution or type argument inference fails, we want to report the
@@ -20599,12 +20590,7 @@ namespace ts {
20599
20590
// skip the checkApplicableSignature check.
20600
20591
if (reportErrors) {
20601
20592
if (candidateForArgumentError) {
20602
- // excludeArgument is undefined, in this case also equivalent to [undefined, undefined, ...]
20603
- // The importance of excludeArgument is to prevent us from typing function expression parameters
20604
- // in arguments too early. If possible, we'd like to only type them once we know the correct
20605
- // overload. However, this matters for the case where the call is correct. When the call is
20606
- // an error, we don't need to exclude any arguments, although it would cause no harm to do so.
20607
- checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, /*excludeArgument*/ undefined, /*reportErrors*/ true);
20593
+ checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, CheckMode.Normal, /*reportErrors*/ true);
20608
20594
}
20609
20595
else if (candidateForArgumentArityError) {
20610
20596
diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args));
@@ -20638,7 +20624,7 @@ namespace ts {
20638
20624
if (typeArguments || !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) {
20639
20625
return undefined;
20640
20626
}
20641
- if (!checkApplicableSignature(node, args, candidate, relation, excludeArgument , /*reportErrors*/ false)) {
20627
+ if (!checkApplicableSignature(node, args, candidate, relation, CheckMode.Normal , /*reportErrors*/ false)) {
20642
20628
candidateForArgumentError = candidate;
20643
20629
return undefined;
20644
20630
}
@@ -20665,7 +20651,8 @@ namespace ts {
20665
20651
}
20666
20652
else {
20667
20653
inferenceContext = createInferenceContext(candidate.typeParameters, candidate, /*flags*/ isInJSFile(node) ? InferenceFlags.AnyDefault : InferenceFlags.None);
20668
- typeArgumentTypes = inferTypeArguments(node, candidate, args, excludeArgument || emptyArray, inferenceContext);
20654
+ typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode | CheckMode.SkipGenericFunctions, inferenceContext);
20655
+ argCheckMode |= inferenceContext.flags & InferenceFlags.SkippedGenericFunction ? CheckMode.SkipGenericFunctions : CheckMode.Normal;
20669
20656
}
20670
20657
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
20671
20658
// If the original signature has a generic rest type, instantiation may produce a
@@ -20678,20 +20665,20 @@ namespace ts {
20678
20665
else {
20679
20666
checkCandidate = candidate;
20680
20667
}
20681
- if (!checkApplicableSignature(node, args, checkCandidate, relation, excludeArgument || inferenceContext && emptyArray , /*reportErrors*/ false)) {
20668
+ if (!checkApplicableSignature(node, args, checkCandidate, relation, argCheckMode , /*reportErrors*/ false)) {
20682
20669
// Give preference to error candidates that have no rest parameters (as they are more specific)
20683
20670
if (!candidateForArgumentError || getEffectiveRestType(candidateForArgumentError) || !getEffectiveRestType(checkCandidate)) {
20684
20671
candidateForArgumentError = checkCandidate;
20685
20672
}
20686
20673
continue;
20687
20674
}
20688
- if (excludeArgument || inferenceContext && inferenceContext.flags & InferenceFlags.SkippedGenericFunction ) {
20675
+ if (argCheckMode ) {
20689
20676
// If one or more context sensitive arguments were excluded, we start including
20690
20677
// them now (and keeping do so for any subsequent candidates) and perform a second
20691
20678
// round of type inference and applicability checking for this particular candidate.
20692
- excludeArgument = undefined ;
20679
+ argCheckMode = CheckMode.Normal ;
20693
20680
if (inferenceContext) {
20694
- const typeArgumentTypes = inferTypeArguments(node, candidate, args, excludeArgument , inferenceContext);
20681
+ const typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode , inferenceContext);
20695
20682
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
20696
20683
// If the original signature has a generic rest type, instantiation may produce a
20697
20684
// signature with different arity and we need to perform another arity check.
@@ -20700,7 +20687,7 @@ namespace ts {
20700
20687
continue;
20701
20688
}
20702
20689
}
20703
- if (!checkApplicableSignature(node, args, checkCandidate, relation, excludeArgument , /*reportErrors*/ false)) {
20690
+ if (!checkApplicableSignature(node, args, checkCandidate, relation, argCheckMode , /*reportErrors*/ false)) {
20704
20691
// Give preference to error candidates that have no rest parameters (as they are more specific)
20705
20692
if (!candidateForArgumentError || getEffectiveRestType(candidateForArgumentError) || !getEffectiveRestType(checkCandidate)) {
20706
20693
candidateForArgumentError = checkCandidate;
@@ -20716,21 +20703,6 @@ namespace ts {
20716
20703
}
20717
20704
}
20718
20705
20719
- function getExcludeArgument(args: ReadonlyArray<Expression>): boolean[] | undefined {
20720
- let excludeArgument: boolean[] | undefined;
20721
- // We do not need to call `getEffectiveArgumentCount` here as it only
20722
- // applies when calculating the number of arguments for a decorator.
20723
- for (let i = 0; i < args.length; i++) {
20724
- if (isContextSensitive(args[i])) {
20725
- if (!excludeArgument) {
20726
- excludeArgument = new Array(args.length);
20727
- }
20728
- excludeArgument[i] = true;
20729
- }
20730
- }
20731
- return excludeArgument;
20732
- }
20733
-
20734
20706
// No signature was applicable. We have already reported the errors for the invalid signature.
20735
20707
// If this is a type resolution session, e.g. Language Service, try to get better information than anySignature.
20736
20708
function getCandidateForOverloadFailure(
@@ -20830,7 +20802,7 @@ namespace ts {
20830
20802
20831
20803
function inferSignatureInstantiationForOverloadFailure(node: CallLikeExpression, typeParameters: ReadonlyArray<TypeParameter>, candidate: Signature, args: ReadonlyArray<Expression>): Signature {
20832
20804
const inferenceContext = createInferenceContext(typeParameters, candidate, /*flags*/ isInJSFile(node) ? InferenceFlags.AnyDefault : InferenceFlags.None);
20833
- const typeArgumentTypes = inferTypeArguments(node, candidate, args, getExcludeArgument(args) || emptyArray , inferenceContext);
20805
+ const typeArgumentTypes = inferTypeArguments(node, candidate, args, CheckMode.SkipContextSensitive | CheckMode.SkipGenericFunctions , inferenceContext);
20834
20806
return createSignatureInstantiation(candidate, typeArgumentTypes);
20835
20807
}
20836
20808
0 commit comments