Skip to content

Commit 9a6a4ab

Browse files
authored
Fixed a string completions regression when requested directly in argument position (#55552)
1 parent fe70ec9 commit 9a6a4ab

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/compiler/checker.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1917,6 +1917,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
19171917
var anyType = createIntrinsicType(TypeFlags.Any, "any");
19181918
var autoType = createIntrinsicType(TypeFlags.Any, "any", ObjectFlags.NonInferrableType);
19191919
var wildcardType = createIntrinsicType(TypeFlags.Any, "any");
1920+
var blockedStringType = createIntrinsicType(TypeFlags.Any, "any");
19201921
var errorType = createIntrinsicType(TypeFlags.Any, "error");
19211922
var unresolvedType = createIntrinsicType(TypeFlags.Any, "unresolved");
19221923
var nonInferrableAnyType = createIntrinsicType(TypeFlags.Any, "any", ObjectFlags.ContainsWideningType);
@@ -25719,7 +25720,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2571925720
const constraint = getConstraintOfTypeParameter(inference.typeParameter);
2572025721
if (constraint) {
2572125722
const instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
25722-
if (!inferredType || inferredType === wildcardType || !context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
25723+
if (!inferredType || inferredType === blockedStringType || !context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
2572325724
// If the fallback type satisfies the constraint, we pick it. Otherwise, we pick the constraint.
2572425725
inference.inferredType = fallbackType && context.compareTypes(fallbackType, getTypeWithThisArgument(instantiatedConstraint, fallbackType)) ? fallbackType : instantiatedConstraint;
2572525726
}
@@ -38535,7 +38536,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3853538536
case SyntaxKind.NoSubstitutionTemplateLiteral:
3853638537
case SyntaxKind.StringLiteral:
3853738538
return hasSkipDirectInferenceFlag(node) ?
38538-
wildcardType :
38539+
blockedStringType :
3853938540
getFreshTypeOfLiteralType(getStringLiteralType((node as StringLiteralLike).text));
3854038541
case SyntaxKind.NumericLiteral: {
3854138542
checkGrammarNumericLiteral(node as NumericLiteral);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @strict: true
4+
5+
//// // https://github.com/microsoft/TypeScript/issues/55545
6+
//// enum myEnum {
7+
//// valA = "valA",
8+
//// valB = "valB",
9+
//// }
10+
////
11+
//// interface myEnumParamMapping {
12+
//// ["valA"]: "1" | "2";
13+
//// ["valB"]: "3" | "4";
14+
//// }
15+
////
16+
//// function myFunction<K extends keyof typeof myEnum>(
17+
//// a: K,
18+
//// b: myEnumParamMapping[K],
19+
//// ) {}
20+
////
21+
//// myFunction("valA", "/*ts1*/");
22+
//// myFunction("valA", `/*ts2*/`);
23+
////
24+
//// function myFunction2<K extends keyof typeof myEnum>(
25+
//// a: K,
26+
//// { b }: { b: myEnumParamMapping[K] },
27+
//// ) {}
28+
////
29+
//// myFunction2("valA", { b: "/*ts3*/" });
30+
//// myFunction2("valA", { b: `/*ts4*/` });
31+
32+
verify.completions({
33+
marker: ["ts1", "ts2", "ts3", "ts4"],
34+
exact: ["1", "2"]
35+
});

0 commit comments

Comments
 (0)