@@ -174,12 +174,6 @@ namespace ts {
174
174
IsForSignatureHelp = 1 << 4, // Call resolution for purposes of signature help
175
175
}
176
176
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
-
183
177
const enum AccessFlags {
184
178
None = 0,
185
179
NoIndexSignatures = 1 << 0,
@@ -454,9 +448,9 @@ namespace ts {
454
448
},
455
449
getAugmentedPropertiesOfType,
456
450
getRootSymbols,
457
- getContextualType: nodeIn => {
451
+ getContextualType: ( nodeIn: Expression, contextFlags?: ContextFlags) => {
458
452
const node = getParseTreeNode(nodeIn, isExpression);
459
- return node ? getContextualType(node) : undefined;
453
+ return node ? getContextualType(node, contextFlags ) : undefined;
460
454
},
461
455
getContextualTypeForObjectLiteralElement: nodeIn => {
462
456
const node = getParseTreeNode(nodeIn, isObjectLiteralElementLike);
@@ -20948,19 +20942,23 @@ namespace ts {
20948
20942
}
20949
20943
20950
20944
// 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 {
20952
20946
const args = getEffectiveCallArguments(callTarget);
20953
20947
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 );
20955
20949
}
20956
20950
20957
- function getContextualTypeForArgumentAtIndex(callTarget: CallLikeExpression, argIndex: number): Type {
20951
+ function getContextualTypeForArgumentAtIndex(callTarget: CallLikeExpression, argIndex: number, contextFlags?: ContextFlags ): Type {
20958
20952
// If we're already in the process of resolving the given signature, don't resolve again as
20959
20953
// that could cause infinite recursion. Instead, return anySignature.
20960
20954
const signature = getNodeLinks(callTarget).resolvedSignature === resolvingSignature ? resolvingSignature : getResolvedSignature(callTarget);
20961
20955
if (isJsxOpeningLikeElement(callTarget) && argIndex === 0) {
20962
20956
return getEffectiveFirstArgumentForJsxSignature(signature, callTarget);
20963
20957
}
20958
+ if (contextFlags && contextFlags & ContextFlags.Completion && signature.target) {
20959
+ const baseSignature = getBaseSignature(signature.target);
20960
+ return intersectTypes(getTypeAtPosition(signature, argIndex), getTypeAtPosition(baseSignature, argIndex));
20961
+ }
20964
20962
return getTypeAtPosition(signature, argIndex);
20965
20963
}
20966
20964
@@ -21352,7 +21350,7 @@ namespace ts {
21352
21350
}
21353
21351
/* falls through */
21354
21352
case SyntaxKind.NewExpression:
21355
- return getContextualTypeForArgument(<CallExpression | NewExpression>parent, node);
21353
+ return getContextualTypeForArgument(<CallExpression | NewExpression>parent, node, contextFlags );
21356
21354
case SyntaxKind.TypeAssertionExpression:
21357
21355
case SyntaxKind.AsExpression:
21358
21356
return isConstTypeReference((<AssertionExpression>parent).type) ? undefined : getTypeFromTypeNode((<AssertionExpression>parent).type);
0 commit comments