Skip to content

Commit efc343a

Browse files
authored
Remove CheckMode.IsForStringLiteralArgumentCompletions (#55867)
1 parent df5093e commit efc343a

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/compiler/checker.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -1265,11 +1265,10 @@ export const enum CheckMode {
12651265
SkipContextSensitive = 1 << 2, // Skip context sensitive function expressions
12661266
SkipGenericFunctions = 1 << 3, // Skip single signature generic functions
12671267
IsForSignatureHelp = 1 << 4, // Call resolution for purposes of signature help
1268-
IsForStringLiteralArgumentCompletions = 1 << 5, // Do not infer from the argument currently being typed
1269-
RestBindingElement = 1 << 6, // Checking a type that is going to be used to determine the type of a rest binding element
1268+
RestBindingElement = 1 << 5, // Checking a type that is going to be used to determine the type of a rest binding element
12701269
// e.g. in `const { a, ...rest } = foo`, when checking the type of `foo` to determine the type of `rest`,
12711270
// we need to preserve generic types instead of substituting them for constraints
1272-
TypeOnly = 1 << 7, // Called from getTypeOfExpression, diagnostics may be omitted
1271+
TypeOnly = 1 << 6, // Called from getTypeOfExpression, diagnostics may be omitted
12731272
}
12741273

12751274
/** @internal */
@@ -1841,7 +1840,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
18411840
const candidates: Signature[] = [];
18421841

18431842
// first, get candidates when inference is blocked from the source node.
1844-
runWithInferenceBlockedFromSourceNode(editingArgument, () => getResolvedSignatureWorker(call, candidates, /*argumentCount*/ undefined, CheckMode.IsForStringLiteralArgumentCompletions));
1843+
runWithInferenceBlockedFromSourceNode(editingArgument, () => getResolvedSignatureWorker(call, candidates, /*argumentCount*/ undefined, CheckMode.Normal));
18451844
for (const candidate of candidates) {
18461845
candidatesSet.add(candidate);
18471846
}
@@ -25010,7 +25009,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2501025009
if (!couldContainTypeVariables(target)) {
2501125010
return;
2501225011
}
25013-
if (source === wildcardType) {
25012+
if (source === wildcardType || source === blockedStringType) {
2501425013
// We are inferring from an 'any' type. We want to infer this type for every type parameter
2501525014
// referenced in the target type, so we record it as the propagation type and infer from the
2501625015
// target to itself. Then, as we find candidates we substitute the propagation type.
@@ -25110,14 +25109,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2511025109
return;
2511125110
}
2511225111
if (!inference.isFixed) {
25112+
const candidate = propagationType || source;
25113+
if (candidate === blockedStringType) {
25114+
return;
25115+
}
2511325116
if (inference.priority === undefined || priority < inference.priority) {
2511425117
inference.candidates = undefined;
2511525118
inference.contraCandidates = undefined;
2511625119
inference.topLevel = true;
2511725120
inference.priority = priority;
2511825121
}
2511925122
if (priority === inference.priority) {
25120-
const candidate = propagationType || source;
2512125123
// We make contravariant inferences only if we are in a pure contravariant position,
2512225124
// i.e. only if we have not descended into a bivariant position.
2512325125
if (contravariant && !bivariant) {
@@ -25850,7 +25852,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2585025852
const constraint = getConstraintOfTypeParameter(inference.typeParameter);
2585125853
if (constraint) {
2585225854
const instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
25853-
if (!inferredType || inferredType === blockedStringType || !context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
25855+
if (!inferredType || !context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
2585425856
// If the fallback type satisfies the constraint, we pick it. Otherwise, we pick the constraint.
2585525857
inference.inferredType = fallbackType && context.compareTypes(fallbackType, getTypeWithThisArgument(instantiatedConstraint, fallbackType)) ? fallbackType : instantiatedConstraint;
2585625858
}
@@ -33284,7 +33286,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3328433286

3328533287
for (let i = 0; i < argCount; i++) {
3328633288
const arg = args[i];
33287-
if (arg.kind !== SyntaxKind.OmittedExpression && !(checkMode & CheckMode.IsForStringLiteralArgumentCompletions && hasSkipDirectInferenceFlag(arg))) {
33289+
if (arg.kind !== SyntaxKind.OmittedExpression) {
3328833290
const paramType = getTypeAtPosition(signature, i);
3328933291
if (couldContainTypeVariables(paramType)) {
3329033292
const argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
@@ -33934,7 +33936,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3393433936
// decorators are applied to a declaration by the emitter, and not to an expression.
3393533937
const isSingleNonGenericCandidate = candidates.length === 1 && !candidates[0].typeParameters;
3393633938
let argCheckMode = !isDecorator && !isSingleNonGenericCandidate && some(args, isContextSensitive) ? CheckMode.SkipContextSensitive : CheckMode.Normal;
33937-
argCheckMode |= checkMode & CheckMode.IsForStringLiteralArgumentCompletions;
3393833939

3393933940
// The following variables are captured and modified by calls to chooseOverload.
3394033941
// If overload resolution or type argument inference fails, we want to report the

tests/cases/fourslash/stringCompletionsFromGenericConditionalTypesUsingTemplateLiteralTypes.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@
2828
//// const shallowExpression = parse("foo|/*ts*/")
2929
//// const nestedExpression = parse({ prop: "foo|/*ts2*/" })
3030

31-
verify.completions({ marker: ["ts", "ts2"], exact: ["foo|foo", "foo|bar", "foo|baz"] });
31+
verify.completions({ marker: ["ts"], exact: ["foo", "bar", "baz", "foo|foo", "foo|bar", "foo|baz"] });
32+
verify.completions({ marker: ["ts2"], exact: ["foo|foo", "foo|bar", "foo|baz"] });

0 commit comments

Comments
 (0)