Skip to content

Commit 26c1127

Browse files
committed
Remove CheckMode.IsForStringLiteralArgumentCompletions
1 parent 52374d6 commit 26c1127

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,11 +1258,10 @@ export const enum CheckMode {
12581258
SkipContextSensitive = 1 << 2, // Skip context sensitive function expressions
12591259
SkipGenericFunctions = 1 << 3, // Skip single signature generic functions
12601260
IsForSignatureHelp = 1 << 4, // Call resolution for purposes of signature help
1261-
IsForStringLiteralArgumentCompletions = 1 << 5, // Do not infer from the argument currently being typed
1262-
RestBindingElement = 1 << 6, // Checking a type that is going to be used to determine the type of a rest binding element
1261+
RestBindingElement = 1 << 5, // Checking a type that is going to be used to determine the type of a rest binding element
12631262
// e.g. in `const { a, ...rest } = foo`, when checking the type of `foo` to determine the type of `rest`,
12641263
// we need to preserve generic types instead of substituting them for constraints
1265-
TypeOnly = 1 << 7, // Called from getTypeOfExpression, diagnostics may be omitted
1264+
TypeOnly = 1 << 6, // Called from getTypeOfExpression, diagnostics may be omitted
12661265
}
12671266

12681267
/** @internal */
@@ -1836,7 +1835,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
18361835
const candidates: Signature[] = [];
18371836

18381837
// first, get candidates when inference is blocked from the source node.
1839-
runWithInferenceBlockedFromSourceNode(editingArgument, () => getResolvedSignatureWorker(call, candidates, /*argumentCount*/ undefined, CheckMode.IsForStringLiteralArgumentCompletions));
1838+
runWithInferenceBlockedFromSourceNode(editingArgument, () => getResolvedSignatureWorker(call, candidates, /*argumentCount*/ undefined, CheckMode.Normal));
18401839
for (const candidate of candidates) {
18411840
candidatesSet.add(candidate);
18421841
}
@@ -24913,7 +24912,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2491324912
if (!couldContainTypeVariables(target)) {
2491424913
return;
2491524914
}
24916-
if (source === wildcardType) {
24915+
if (source === wildcardType || source === blockedStringType) {
2491724916
// We are inferring from an 'any' type. We want to infer this type for every type parameter
2491824917
// referenced in the target type, so we record it as the propagation type and infer from the
2491924918
// target to itself. Then, as we find candidates we substitute the propagation type.
@@ -25013,14 +25012,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2501325012
return;
2501425013
}
2501525014
if (!inference.isFixed) {
25015+
const candidate = propagationType || source;
25016+
if (candidate === blockedStringType) {
25017+
return;
25018+
}
2501625019
if (inference.priority === undefined || priority < inference.priority) {
2501725020
inference.candidates = undefined;
2501825021
inference.contraCandidates = undefined;
2501925022
inference.topLevel = true;
2502025023
inference.priority = priority;
2502125024
}
2502225025
if (priority === inference.priority) {
25023-
const candidate = propagationType || source;
2502425026
// We make contravariant inferences only if we are in a pure contravariant position,
2502525027
// i.e. only if we have not descended into a bivariant position.
2502625028
if (contravariant && !bivariant) {
@@ -25753,7 +25755,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2575325755
const constraint = getConstraintOfTypeParameter(inference.typeParameter);
2575425756
if (constraint) {
2575525757
const instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
25756-
if (!inferredType || inferredType === blockedStringType || !context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
25758+
if (!inferredType || !context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
2575725759
// If the fallback type satisfies the constraint, we pick it. Otherwise, we pick the constraint.
2575825760
inference.inferredType = fallbackType && context.compareTypes(fallbackType, getTypeWithThisArgument(instantiatedConstraint, fallbackType)) ? fallbackType : instantiatedConstraint;
2575925761
}
@@ -33123,7 +33125,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3312333125

3312433126
for (let i = 0; i < argCount; i++) {
3312533127
const arg = args[i];
33126-
if (arg.kind !== SyntaxKind.OmittedExpression && !(checkMode & CheckMode.IsForStringLiteralArgumentCompletions && hasSkipDirectInferenceFlag(arg))) {
33128+
if (arg.kind !== SyntaxKind.OmittedExpression) {
3312733129
const paramType = getTypeAtPosition(signature, i);
3312833130
if (couldContainTypeVariables(paramType)) {
3312933131
const argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
@@ -33765,7 +33767,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3376533767
// decorators are applied to a declaration by the emitter, and not to an expression.
3376633768
const isSingleNonGenericCandidate = candidates.length === 1 && !candidates[0].typeParameters;
3376733769
let argCheckMode = !isDecorator && !isSingleNonGenericCandidate && some(args, isContextSensitive) ? CheckMode.SkipContextSensitive : CheckMode.Normal;
33768-
argCheckMode |= checkMode & CheckMode.IsForStringLiteralArgumentCompletions;
3376933770

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

tests/cases/fourslash/stringCompletionsFromGenericConditionalTypesUsingTemplateLiteralTypes.ts

Lines changed: 2 additions & 1 deletion
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)