From 0a12f3e68393603cbb5e7058be6965b2dd6b3604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sat, 29 Jul 2023 00:15:27 +0200 Subject: [PATCH] add fourslash test and fix the reduction issue --- src/compiler/checker.ts | 6 +++++- ...ringLiteralCompletionsForOpenEndedTemplateLiteralType.ts | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/stringLiteralCompletionsForOpenEndedTemplateLiteralType.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d48ecea74aae5..21e03819e6ade 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16439,7 +16439,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function removeStringLiteralsMatchedByTemplateLiterals(types: Type[]) { - const templates = filter(types, t => !!(t.flags & TypeFlags.TemplateLiteral) && isPatternLiteralType(t)) as TemplateLiteralType[]; + const templates = filter(types, t => + !!(t.flags & TypeFlags.TemplateLiteral) && + isPatternLiteralType(t) && + (t as TemplateLiteralType).types.every(t => !(t.flags & TypeFlags.Intersection) || !areIntersectedTypesAvoidingPrimitiveReduction((t as IntersectionType).types)) + ) as TemplateLiteralType[]; if (templates.length) { let i = types.length; while (i > 0) { diff --git a/tests/cases/fourslash/stringLiteralCompletionsForOpenEndedTemplateLiteralType.ts b/tests/cases/fourslash/stringLiteralCompletionsForOpenEndedTemplateLiteralType.ts new file mode 100644 index 0000000000000..92c02a23a2854 --- /dev/null +++ b/tests/cases/fourslash/stringLiteralCompletionsForOpenEndedTemplateLiteralType.ts @@ -0,0 +1,6 @@ +/// + +//// function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {} +//// conversionTest("/**/"); + +verify.completions({ marker: "", exact: ["downcast", "dataDowncast", "editingDowncast"] });