Skip to content

Commit f5f1403

Browse files
committed
add fourslash test and fix the reduction issue
1 parent 3458d37 commit f5f1403

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16439,7 +16439,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1643916439
}
1644016440

1644116441
function removeStringLiteralsMatchedByTemplateLiterals(types: Type[]) {
16442-
const templates = filter(types, t => !!(t.flags & TypeFlags.TemplateLiteral) && isPatternLiteralType(t)) as TemplateLiteralType[];
16442+
const templates = filter(types, t =>
16443+
!!(t.flags & TypeFlags.TemplateLiteral) &&
16444+
isPatternLiteralType(t) &&
16445+
(t as TemplateLiteralType).types.every(t => !(t.flags & TypeFlags.Intersection) || !areIntersectedTypesAvoidingPrimitiveReduction((t as IntersectionType).types))
16446+
) as TemplateLiteralType[];
1644316447
if (templates.length) {
1644416448
let i = types.length;
1644516449
while (i > 0) {

tests/baselines/reference/templateLiteralTypesPatterns.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,20 +638,20 @@ export abstract class BB {
638638
// repro from https://github.com/microsoft/TypeScript/issues/54177#issuecomment-1538436654
639639
function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {}
640640
>conversionTest : (groupName: "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) => void
641-
>groupName : `${string & {}}Downcast` | "downcast"
641+
>groupName : `${string & {}}Downcast` | "downcast" | "dataDowncast" | "editingDowncast"
642642

643643
conversionTest("testDowncast");
644644
>conversionTest("testDowncast") : void
645-
>conversionTest : (groupName: `${string & {}}Downcast` | "downcast") => void
645+
>conversionTest : (groupName: `${string & {}}Downcast` | "downcast" | "dataDowncast" | "editingDowncast") => void
646646
>"testDowncast" : "testDowncast"
647647

648648
function conversionTest2(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) {}
649649
>conversionTest2 : (groupName: "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) => void
650-
>groupName : "downcast" | `${{} & string}Downcast`
650+
>groupName : "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`
651651

652652
conversionTest2("testDowncast");
653653
>conversionTest2("testDowncast") : void
654-
>conversionTest2 : (groupName: "downcast" | `${{} & string}Downcast`) => void
654+
>conversionTest2 : (groupName: "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) => void
655655
>"testDowncast" : "testDowncast"
656656

657657
function foo(str: `${`a${string}` & `${string}a`}Test`) {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {}
4+
//// conversionTest("/**/");
5+
6+
verify.completions({ marker: "", exact: ["downcast", "dataDowncast", "editingDowncast"] });

0 commit comments

Comments
 (0)