@@ -174,12 +174,6 @@ namespace ts {
174174 IsForSignatureHelp = 1 << 4, // Call resolution for purposes of signature help
175175 }
176176
177- const enum ContextFlags {
178- None = 0,
179- Signature = 1 << 0, // Obtaining contextual signature
180- NoConstraints = 1 << 1, // Don't obtain type variable constraints
181- }
182-
183177 const enum AccessFlags {
184178 None = 0,
185179 NoIndexSignatures = 1 << 0,
@@ -454,9 +448,9 @@ namespace ts {
454448 },
455449 getAugmentedPropertiesOfType,
456450 getRootSymbols,
457- getContextualType: nodeIn => {
451+ getContextualType: ( nodeIn: Expression, contextFlags?: ContextFlags) => {
458452 const node = getParseTreeNode(nodeIn, isExpression);
459- return node ? getContextualType(node) : undefined;
453+ return node ? getContextualType(node, contextFlags ) : undefined;
460454 },
461455 getContextualTypeForObjectLiteralElement: nodeIn => {
462456 const node = getParseTreeNode(nodeIn, isObjectLiteralElementLike);
@@ -20948,19 +20942,23 @@ namespace ts {
2094820942 }
2094920943
2095020944 // In a typed function call, an argument or substitution expression is contextually typed by the type of the corresponding parameter.
20951- function getContextualTypeForArgument(callTarget: CallLikeExpression, arg: Expression): Type | undefined {
20945+ function getContextualTypeForArgument(callTarget: CallLikeExpression, arg: Expression, contextFlags?: ContextFlags ): Type | undefined {
2095220946 const args = getEffectiveCallArguments(callTarget);
2095320947 const argIndex = args.indexOf(arg); // -1 for e.g. the expression of a CallExpression, or the tag of a TaggedTemplateExpression
20954- return argIndex === -1 ? undefined : getContextualTypeForArgumentAtIndex(callTarget, argIndex);
20948+ return argIndex === -1 ? undefined : getContextualTypeForArgumentAtIndex(callTarget, argIndex, contextFlags );
2095520949 }
2095620950
20957- function getContextualTypeForArgumentAtIndex(callTarget: CallLikeExpression, argIndex: number): Type {
20951+ function getContextualTypeForArgumentAtIndex(callTarget: CallLikeExpression, argIndex: number, contextFlags?: ContextFlags ): Type {
2095820952 // If we're already in the process of resolving the given signature, don't resolve again as
2095920953 // that could cause infinite recursion. Instead, return anySignature.
2096020954 const signature = getNodeLinks(callTarget).resolvedSignature === resolvingSignature ? resolvingSignature : getResolvedSignature(callTarget);
2096120955 if (isJsxOpeningLikeElement(callTarget) && argIndex === 0) {
2096220956 return getEffectiveFirstArgumentForJsxSignature(signature, callTarget);
2096320957 }
20958+ if (contextFlags && contextFlags & ContextFlags.Completion && signature.target) {
20959+ const baseSignature = getBaseSignature(signature.target);
20960+ return intersectTypes(getTypeAtPosition(signature, argIndex), getTypeAtPosition(baseSignature, argIndex));
20961+ }
2096420962 return getTypeAtPosition(signature, argIndex);
2096520963 }
2096620964
@@ -21352,7 +21350,7 @@ namespace ts {
2135221350 }
2135321351 /* falls through */
2135421352 case SyntaxKind.NewExpression:
21355- return getContextualTypeForArgument(<CallExpression | NewExpression>parent, node);
21353+ return getContextualTypeForArgument(<CallExpression | NewExpression>parent, node, contextFlags );
2135621354 case SyntaxKind.TypeAssertionExpression:
2135721355 case SyntaxKind.AsExpression:
2135821356 return isConstTypeReference((<AssertionExpression>parent).type) ? undefined : getTypeFromTypeNode((<AssertionExpression>parent).type);
0 commit comments