diff --git a/src/services/completions.ts b/src/services/completions.ts
index c55783b060a72..7ff65c94e4212 100644
--- a/src/services/completions.ts
+++ b/src/services/completions.ts
@@ -2905,7 +2905,10 @@ function getCompletionData(
log("getCompletionData: Semantic work: " + (timestamp() - semanticStart));
const contextualType = previousToken && getContextualType(previousToken, position, sourceFile, typeChecker);
- const literals = mapDefined(
+ // exclude literal suggestions after (#51667) and after closing quote (#52675)
+ // for strings getStringLiteralCompletions handles completions
+ const isLiteralExpected = !tryCast(previousToken, isStringLiteralLike) && !isJsxIdentifierExpected;
+ const literals = !isLiteralExpected ? [] : mapDefined(
contextualType && (contextualType.isUnion() ? contextualType.types : [contextualType]),
t => t.isLiteral() && !(t.flags & TypeFlags.EnumLiteral) ? t.value : undefined);
diff --git a/tests/cases/fourslash/completionsLiterals.ts b/tests/cases/fourslash/completionsLiterals.ts
index e25976417d381..5c1f574cc6e7a 100644
--- a/tests/cases/fourslash/completionsLiterals.ts
+++ b/tests/cases/fourslash/completionsLiterals.ts
@@ -2,6 +2,7 @@
////const x: 0 | "one" = /**/;
////const y: 0 | "one" | 1n = /*1*/;
+////const y2: 0 | "one" | 1n = 'one'/*2*/;
verify.completions({
marker: "",
@@ -20,3 +21,9 @@ verify.completions({
],
isNewIdentifierLocation: true,
});
+verify.completions({
+ marker: "2",
+ excludes: [
+ '"one"'
+ ],
+});
diff --git a/tests/cases/fourslash/stringLiteralCompletionsInJsxAttributeInitializer.ts b/tests/cases/fourslash/stringLiteralCompletionsInJsxAttributeInitializer.ts
index 6e19605d7d064..ca5afa2a45d63 100644
--- a/tests/cases/fourslash/stringLiteralCompletionsInJsxAttributeInitializer.ts
+++ b/tests/cases/fourslash/stringLiteralCompletionsInJsxAttributeInitializer.ts
@@ -2,10 +2,15 @@
// @jsx: preserve
// @filename: /a.tsx
-////type Props = { a: number } | { b: "somethingelse" };
+////type Props = { a: number } | { b: "somethingelse", c: 0 | 1 };
////declare function Foo(args: Props): any
////
////const a1 =
////const a2 =
+////const a3 =
+////const a4 =
+////const a5 =
verify.completions({ marker: ["1", "2"], exact: ["somethingelse"] });
+verify.completions({ marker: ["3", "4"], excludes: ['"somethingelse"'], });
+verify.completions({ marker: ["5"], excludes: ["0", "1"], });