@@ -467,7 +467,29 @@ namespace ts {
467
467
getRootSymbols,
468
468
getContextualType: (nodeIn: Expression, contextFlags?: ContextFlags) => {
469
469
const node = getParseTreeNode(nodeIn, isExpression);
470
- return node ? getContextualType(node, contextFlags) : undefined;
470
+ if (!node) {
471
+ return undefined;
472
+ }
473
+ const containingCall = findAncestor(node, isCallLikeExpression);
474
+ const containingCallResolvedSignature = containingCall && getNodeLinks(containingCall).resolvedSignature;
475
+ if (contextFlags! & ContextFlags.Completions && containingCall) {
476
+ let toMarkSkip = node as Node;
477
+ do {
478
+ getNodeLinks(toMarkSkip).skipDirectInference = true;
479
+ toMarkSkip = toMarkSkip.parent;
480
+ } while (toMarkSkip && toMarkSkip !== containingCall);
481
+ getNodeLinks(containingCall).resolvedSignature = undefined;
482
+ }
483
+ const result = getContextualType(node, contextFlags);
484
+ if (contextFlags! & ContextFlags.Completions && containingCall) {
485
+ let toMarkSkip = node as Node;
486
+ do {
487
+ getNodeLinks(toMarkSkip).skipDirectInference = undefined;
488
+ toMarkSkip = toMarkSkip.parent;
489
+ } while (toMarkSkip && toMarkSkip !== containingCall);
490
+ getNodeLinks(containingCall).resolvedSignature = containingCallResolvedSignature;
491
+ }
492
+ return result;
471
493
},
472
494
getContextualTypeForObjectLiteralElement: nodeIn => {
473
495
const node = getParseTreeNode(nodeIn, isObjectLiteralElementLike);
@@ -17796,6 +17818,14 @@ namespace ts {
17796
17818
undefined;
17797
17819
}
17798
17820
17821
+ function hasSkipDirectInferenceFlag(node: Node) {
17822
+ return !!getNodeLinks(node).skipDirectInference;
17823
+ }
17824
+
17825
+ function isFromInferenceBlockedSource(type: Type) {
17826
+ return !!(type.symbol && some(type.symbol.declarations, hasSkipDirectInferenceFlag));
17827
+ }
17828
+
17799
17829
function inferTypes(inferences: InferenceInfo[], originalSource: Type, originalTarget: Type, priority: InferencePriority = 0, contravariant = false) {
17800
17830
let symbolStack: Symbol[];
17801
17831
let visited: Map<number>;
@@ -17886,7 +17916,7 @@ namespace ts {
17886
17916
// of inference. Also, we exclude inferences for silentNeverType (which is used as a wildcard
17887
17917
// when constructing types from type parameters that had no inference candidates).
17888
17918
if (getObjectFlags(source) & ObjectFlags.NonInferrableType || source === nonInferrableAnyType || source === silentNeverType ||
17889
- (priority & InferencePriority.ReturnType && (source === autoType || source === autoArrayType))) {
17919
+ (priority & InferencePriority.ReturnType && (source === autoType || source === autoArrayType)) || isFromInferenceBlockedSource(source) ) {
17890
17920
return;
17891
17921
}
17892
17922
const inference = getInferenceInfoForType(target);
@@ -18190,7 +18220,7 @@ namespace ts {
18190
18220
// type and then make a secondary inference from that type to T. We make a secondary inference
18191
18221
// such that direct inferences to T get priority over inferences to Partial<T>, for example.
18192
18222
const inference = getInferenceInfoForType((<IndexType>constraintType).type);
18193
- if (inference && !inference.isFixed) {
18223
+ if (inference && !inference.isFixed && !isFromInferenceBlockedSource(source) ) {
18194
18224
const inferredType = inferTypeForHomomorphicMappedType(source, target, <IndexType>constraintType);
18195
18225
if (inferredType) {
18196
18226
// We assign a lower priority to inferences made from types containing non-inferrable
@@ -21449,19 +21479,16 @@ namespace ts {
21449
21479
}
21450
21480
21451
21481
// In a typed function call, an argument or substitution expression is contextually typed by the type of the corresponding parameter.
21452
- function getContextualTypeForArgument(callTarget: CallLikeExpression, arg: Expression, contextFlags?: ContextFlags ): Type | undefined {
21482
+ function getContextualTypeForArgument(callTarget: CallLikeExpression, arg: Expression): Type | undefined {
21453
21483
const args = getEffectiveCallArguments(callTarget);
21454
21484
const argIndex = args.indexOf(arg); // -1 for e.g. the expression of a CallExpression, or the tag of a TaggedTemplateExpression
21455
- return argIndex === -1 ? undefined : getContextualTypeForArgumentAtIndex(callTarget, argIndex, contextFlags );
21485
+ return argIndex === -1 ? undefined : getContextualTypeForArgumentAtIndex(callTarget, argIndex);
21456
21486
}
21457
21487
21458
- function getContextualTypeForArgumentAtIndex(callTarget: CallLikeExpression, argIndex: number, contextFlags?: ContextFlags ): Type {
21488
+ function getContextualTypeForArgumentAtIndex(callTarget: CallLikeExpression, argIndex: number): Type {
21459
21489
// If we're already in the process of resolving the given signature, don't resolve again as
21460
21490
// that could cause infinite recursion. Instead, return anySignature.
21461
- let signature = getNodeLinks(callTarget).resolvedSignature === resolvingSignature ? resolvingSignature : getResolvedSignature(callTarget);
21462
- if (contextFlags && contextFlags & ContextFlags.BaseConstraint && signature.target && !hasTypeArguments(callTarget)) {
21463
- signature = getBaseSignature(signature.target);
21464
- }
21491
+ const signature = getNodeLinks(callTarget).resolvedSignature === resolvingSignature ? resolvingSignature : getResolvedSignature(callTarget);
21465
21492
21466
21493
if (isJsxOpeningLikeElement(callTarget) && argIndex === 0) {
21467
21494
return getEffectiveFirstArgumentForJsxSignature(signature, callTarget);
@@ -21857,7 +21884,7 @@ namespace ts {
21857
21884
}
21858
21885
/* falls through */
21859
21886
case SyntaxKind.NewExpression:
21860
- return getContextualTypeForArgument(<CallExpression | NewExpression>parent, node, contextFlags );
21887
+ return getContextualTypeForArgument(<CallExpression | NewExpression>parent, node);
21861
21888
case SyntaxKind.TypeAssertionExpression:
21862
21889
case SyntaxKind.AsExpression:
21863
21890
return isConstTypeReference((<AssertionExpression>parent).type) ? undefined : getTypeFromTypeNode((<AssertionExpression>parent).type);
@@ -21901,13 +21928,13 @@ namespace ts {
21901
21928
}
21902
21929
21903
21930
function getContextualJsxElementAttributesType(node: JsxOpeningLikeElement, contextFlags?: ContextFlags) {
21904
- if (isJsxOpeningElement(node) && node.parent.contextualType && contextFlags !== ContextFlags.BaseConstraint ) {
21931
+ if (isJsxOpeningElement(node) && node.parent.contextualType && contextFlags !== ContextFlags.Completions ) {
21905
21932
// Contextually applied type is moved from attributes up to the outer jsx attributes so when walking up from the children they get hit
21906
21933
// _However_ to hit them from the _attributes_ we must look for them here; otherwise we'll used the declared type
21907
21934
// (as below) instead!
21908
21935
return node.parent.contextualType;
21909
21936
}
21910
- return getContextualTypeForArgumentAtIndex(node, 0, contextFlags );
21937
+ return getContextualTypeForArgumentAtIndex(node, 0);
21911
21938
}
21912
21939
21913
21940
function getEffectiveFirstArgumentForJsxSignature(signature: Signature, node: JsxOpeningLikeElement) {
0 commit comments