From 8e76d1644e6742dc81ee5773bedbd86641bd1f36 Mon Sep 17 00:00:00 2001 From: "Pranav Senthilnathan (from Dev Box)" Date: Tue, 17 Oct 2023 13:28:45 -0700 Subject: [PATCH 1/2] naive perf change --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9ed6f52c38c71..f71c629fc9584 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16939,7 +16939,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (includes & (TypeFlags.Enum | TypeFlags.Literal | TypeFlags.UniqueESSymbol | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) || includes & TypeFlags.Void && includes & TypeFlags.Undefined) { removeRedundantLiteralTypes(typeSet, includes, !!(unionReduction & UnionReduction.Subtype)); } - if (includes & TypeFlags.StringLiteral && includes & TypeFlags.TemplateLiteral) { + if (unionReduction === UnionReduction.Subtype && (includes & TypeFlags.StringLiteral && includes & TypeFlags.TemplateLiteral)) { removeStringLiteralsMatchedByTemplateLiterals(typeSet); } if (unionReduction === UnionReduction.Subtype) { From fc0924304258aeeb5be10cb67871374841d89b4a Mon Sep 17 00:00:00 2001 From: "Pranav Senthilnathan (from Dev Box)" Date: Thu, 26 Oct 2023 17:45:26 -0700 Subject: [PATCH 2/2] update tests/baselines --- .../reference/templateLiteralTypes3.types | 2 +- .../templateLiteralTypesPatterns.errors.txt | 17 ++- .../reference/templateLiteralTypesPatterns.js | 16 +-- .../templateLiteralTypesPatterns.symbols | 119 ++++++++++-------- .../templateLiteralTypesPatterns.types | 33 ++++- .../literal/templateLiteralTypesPatterns.ts | 9 +- 6 files changed, 122 insertions(+), 74 deletions(-) diff --git a/tests/baselines/reference/templateLiteralTypes3.types b/tests/baselines/reference/templateLiteralTypes3.types index 67115bf715ab6..7f6b1ec9db227 100644 --- a/tests/baselines/reference/templateLiteralTypes3.types +++ b/tests/baselines/reference/templateLiteralTypes3.types @@ -599,5 +599,5 @@ function ft1(t: T, u: Uppercase, u1: Uppercase<`1.${T}.3`>, // Repro from #52685 type Boom = 'abc' | 'def' | `a${string}` | Lowercase; ->Boom : `a${string}` | Lowercase | "def" +>Boom : "abc" | `a${string}` | Lowercase | "def" diff --git a/tests/baselines/reference/templateLiteralTypesPatterns.errors.txt b/tests/baselines/reference/templateLiteralTypesPatterns.errors.txt index cd82afc83981b..a434c8195a4ae 100644 --- a/tests/baselines/reference/templateLiteralTypesPatterns.errors.txt +++ b/tests/baselines/reference/templateLiteralTypesPatterns.errors.txt @@ -55,10 +55,11 @@ templateLiteralTypesPatterns.ts(129,9): error TS2345: Argument of type '"1.1e-10 templateLiteralTypesPatterns.ts(140,1): error TS2322: Type '`a${string}`' is not assignable to type '`a${number}`'. templateLiteralTypesPatterns.ts(141,1): error TS2322: Type '"bno"' is not assignable to type '`a${any}`'. templateLiteralTypesPatterns.ts(160,7): error TS2322: Type '"anything"' is not assignable to type '`${number} ${number}`'. -templateLiteralTypesPatterns.ts(211,5): error TS2345: Argument of type '"abcTest"' is not assignable to parameter of type '`${`a${string}` & `${string}a`}Test`'. +templateLiteralTypesPatterns.ts(178,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'bb' must be of type '`${number}`', but here has type '`${number}` | "0"'. +templateLiteralTypesPatterns.ts(214,5): error TS2345: Argument of type '"abcTest"' is not assignable to parameter of type '`${`a${string}` & `${string}a`}Test`'. -==== templateLiteralTypesPatterns.ts (58 errors) ==== +==== templateLiteralTypesPatterns.ts (59 errors) ==== type RequiresLeadingSlash = `/${string}`; // ok @@ -342,12 +343,18 @@ templateLiteralTypesPatterns.ts(211,5): error TS2345: Argument of type '"abcTest // Remove string literals from unions with matching template literals - let t1: `foo${string}` | 'foo1' | '1foo'; // `foo${string}` | '1foo' - let t2: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo'; // `foo${string}` | '1foo' | 'xfoo' - let t3: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo' | `${number}foo`; // `foo${string}` | xfoo' | `${number}foo` + declare let t1: `foo${string}` | 'foo1' | '1foo'; + let c1 = true ? t1 : t1; // `foo${string}` | '1foo' + declare let t2: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo'; + let c2 = true ? t2 : t2; // `foo${string}` | '1foo' | 'xfoo' + declare let t3: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo' | `${number}foo`; + let c3 = true ? t3 : t3; // `foo${string}` | xfoo' | `${number}foo` var bb: `${number}`; var bb: `${number}` | '0'; + ~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'bb' must be of type '`${number}`', but here has type '`${number}` | "0"'. +!!! related TS6203 templateLiteralTypesPatterns.ts:177:5: 'bb' was also declared here. // Normalize `${string}` to just string diff --git a/tests/baselines/reference/templateLiteralTypesPatterns.js b/tests/baselines/reference/templateLiteralTypesPatterns.js index d66c794e287a8..be84f62b17ef0 100644 --- a/tests/baselines/reference/templateLiteralTypesPatterns.js +++ b/tests/baselines/reference/templateLiteralTypesPatterns.js @@ -170,9 +170,12 @@ var aa: '0' & `${number}`; // Remove string literals from unions with matching template literals -let t1: `foo${string}` | 'foo1' | '1foo'; // `foo${string}` | '1foo' -let t2: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo'; // `foo${string}` | '1foo' | 'xfoo' -let t3: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo' | `${number}foo`; // `foo${string}` | xfoo' | `${number}foo` +declare let t1: `foo${string}` | 'foo1' | '1foo'; +let c1 = true ? t1 : t1; // `foo${string}` | '1foo' +declare let t2: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo'; +let c2 = true ? t2 : t2; // `foo${string}` | '1foo' | 'xfoo' +declare let t3: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo' | `${number}foo`; +let c3 = true ? t3 : t3; // `foo${string}` | xfoo' | `${number}foo` var bb: `${number}`; var bb: `${number}` | '0'; @@ -337,10 +340,9 @@ var exampleGood = "1 2"; // ok // Repro from #41161 var aa; var aa; -// Remove string literals from unions with matching template literals -var t1; // `foo${string}` | '1foo' -var t2; // `foo${string}` | '1foo' | 'xfoo' -var t3; // `foo${string}` | xfoo' | `${number}foo` +var c1 = true ? t1 : t1; // `foo${string}` | '1foo' +var c2 = true ? t2 : t2; // `foo${string}` | '1foo' | 'xfoo' +var c3 = true ? t3 : t3; // `foo${string}` | xfoo' | `${number}foo` var bb; var bb; function ff1(x) { diff --git a/tests/baselines/reference/templateLiteralTypesPatterns.symbols b/tests/baselines/reference/templateLiteralTypesPatterns.symbols index cc508d2680959..5d74495a0393f 100644 --- a/tests/baselines/reference/templateLiteralTypesPatterns.symbols +++ b/tests/baselines/reference/templateLiteralTypesPatterns.symbols @@ -405,110 +405,125 @@ var aa: '0' & `${number}`; // Remove string literals from unions with matching template literals -let t1: `foo${string}` | 'foo1' | '1foo'; // `foo${string}` | '1foo' ->t1 : Symbol(t1, Decl(templateLiteralTypesPatterns.ts, 169, 3)) +declare let t1: `foo${string}` | 'foo1' | '1foo'; +>t1 : Symbol(t1, Decl(templateLiteralTypesPatterns.ts, 169, 11)) -let t2: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo'; // `foo${string}` | '1foo' | 'xfoo' ->t2 : Symbol(t2, Decl(templateLiteralTypesPatterns.ts, 170, 3)) +let c1 = true ? t1 : t1; // `foo${string}` | '1foo' +>c1 : Symbol(c1, Decl(templateLiteralTypesPatterns.ts, 170, 3)) +>t1 : Symbol(t1, Decl(templateLiteralTypesPatterns.ts, 169, 11)) +>t1 : Symbol(t1, Decl(templateLiteralTypesPatterns.ts, 169, 11)) -let t3: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo' | `${number}foo`; // `foo${string}` | xfoo' | `${number}foo` ->t3 : Symbol(t3, Decl(templateLiteralTypesPatterns.ts, 171, 3)) +declare let t2: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo'; +>t2 : Symbol(t2, Decl(templateLiteralTypesPatterns.ts, 171, 11)) + +let c2 = true ? t2 : t2; // `foo${string}` | '1foo' | 'xfoo' +>c2 : Symbol(c2, Decl(templateLiteralTypesPatterns.ts, 172, 3)) +>t2 : Symbol(t2, Decl(templateLiteralTypesPatterns.ts, 171, 11)) +>t2 : Symbol(t2, Decl(templateLiteralTypesPatterns.ts, 171, 11)) + +declare let t3: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo' | `${number}foo`; +>t3 : Symbol(t3, Decl(templateLiteralTypesPatterns.ts, 173, 11)) + +let c3 = true ? t3 : t3; // `foo${string}` | xfoo' | `${number}foo` +>c3 : Symbol(c3, Decl(templateLiteralTypesPatterns.ts, 174, 3)) +>t3 : Symbol(t3, Decl(templateLiteralTypesPatterns.ts, 173, 11)) +>t3 : Symbol(t3, Decl(templateLiteralTypesPatterns.ts, 173, 11)) var bb: `${number}`; ->bb : Symbol(bb, Decl(templateLiteralTypesPatterns.ts, 173, 3), Decl(templateLiteralTypesPatterns.ts, 174, 3)) +>bb : Symbol(bb, Decl(templateLiteralTypesPatterns.ts, 176, 3), Decl(templateLiteralTypesPatterns.ts, 177, 3)) var bb: `${number}` | '0'; ->bb : Symbol(bb, Decl(templateLiteralTypesPatterns.ts, 173, 3), Decl(templateLiteralTypesPatterns.ts, 174, 3)) +>bb : Symbol(bb, Decl(templateLiteralTypesPatterns.ts, 176, 3), Decl(templateLiteralTypesPatterns.ts, 177, 3)) // Normalize `${string}` to just string type T2S = `${A}${B}`; ->T2S : Symbol(T2S, Decl(templateLiteralTypesPatterns.ts, 174, 26)) ->A : Symbol(A, Decl(templateLiteralTypesPatterns.ts, 178, 9)) ->B : Symbol(B, Decl(templateLiteralTypesPatterns.ts, 178, 26)) ->A : Symbol(A, Decl(templateLiteralTypesPatterns.ts, 178, 9)) ->B : Symbol(B, Decl(templateLiteralTypesPatterns.ts, 178, 26)) +>T2S : Symbol(T2S, Decl(templateLiteralTypesPatterns.ts, 177, 26)) +>A : Symbol(A, Decl(templateLiteralTypesPatterns.ts, 181, 9)) +>B : Symbol(B, Decl(templateLiteralTypesPatterns.ts, 181, 26)) +>A : Symbol(A, Decl(templateLiteralTypesPatterns.ts, 181, 9)) +>B : Symbol(B, Decl(templateLiteralTypesPatterns.ts, 181, 26)) type S10 = `${string}`; // string ->S10 : Symbol(S10, Decl(templateLiteralTypesPatterns.ts, 178, 58)) +>S10 : Symbol(S10, Decl(templateLiteralTypesPatterns.ts, 181, 58)) type S11 = `${string}${string}${string}`; // string ->S11 : Symbol(S11, Decl(templateLiteralTypesPatterns.ts, 180, 23)) +>S11 : Symbol(S11, Decl(templateLiteralTypesPatterns.ts, 183, 23)) type S12 = T2S; // string ->S12 : Symbol(S12, Decl(templateLiteralTypesPatterns.ts, 181, 41)) ->T2S : Symbol(T2S, Decl(templateLiteralTypesPatterns.ts, 174, 26)) +>S12 : Symbol(S12, Decl(templateLiteralTypesPatterns.ts, 184, 41)) +>T2S : Symbol(T2S, Decl(templateLiteralTypesPatterns.ts, 177, 26)) function ff1(x: `${string}-${string}`) { ->ff1 : Symbol(ff1, Decl(templateLiteralTypesPatterns.ts, 182, 31)) ->x : Symbol(x, Decl(templateLiteralTypesPatterns.ts, 184, 13)) +>ff1 : Symbol(ff1, Decl(templateLiteralTypesPatterns.ts, 185, 31)) +>x : Symbol(x, Decl(templateLiteralTypesPatterns.ts, 187, 13)) let s1 = x && 42; // number ->s1 : Symbol(s1, Decl(templateLiteralTypesPatterns.ts, 185, 7)) ->x : Symbol(x, Decl(templateLiteralTypesPatterns.ts, 184, 13)) +>s1 : Symbol(s1, Decl(templateLiteralTypesPatterns.ts, 188, 7)) +>x : Symbol(x, Decl(templateLiteralTypesPatterns.ts, 187, 13)) let s2 = x || 42; // `${string}-${string}` ->s2 : Symbol(s2, Decl(templateLiteralTypesPatterns.ts, 186, 7)) ->x : Symbol(x, Decl(templateLiteralTypesPatterns.ts, 184, 13)) +>s2 : Symbol(s2, Decl(templateLiteralTypesPatterns.ts, 189, 7)) +>x : Symbol(x, Decl(templateLiteralTypesPatterns.ts, 187, 13)) } // Repro from #41651 export type Id = `${TId}-${TId}`; ->Id : Symbol(Id, Decl(templateLiteralTypesPatterns.ts, 187, 1)) ->TA : Symbol(TA, Decl(templateLiteralTypesPatterns.ts, 191, 15)) ->TId : Symbol(TId, Decl(templateLiteralTypesPatterns.ts, 191, 18)) ->TId : Symbol(TId, Decl(templateLiteralTypesPatterns.ts, 191, 18)) ->TId : Symbol(TId, Decl(templateLiteralTypesPatterns.ts, 191, 18)) +>Id : Symbol(Id, Decl(templateLiteralTypesPatterns.ts, 190, 1)) +>TA : Symbol(TA, Decl(templateLiteralTypesPatterns.ts, 194, 15)) +>TId : Symbol(TId, Decl(templateLiteralTypesPatterns.ts, 194, 18)) +>TId : Symbol(TId, Decl(templateLiteralTypesPatterns.ts, 194, 18)) +>TId : Symbol(TId, Decl(templateLiteralTypesPatterns.ts, 194, 18)) export class AA {} ->AA : Symbol(AA, Decl(templateLiteralTypesPatterns.ts, 191, 66)) +>AA : Symbol(AA, Decl(templateLiteralTypesPatterns.ts, 194, 66)) export abstract class BB { ->BB : Symbol(BB, Decl(templateLiteralTypesPatterns.ts, 193, 18)) +>BB : Symbol(BB, Decl(templateLiteralTypesPatterns.ts, 196, 18)) abstract get(id: Id): void; ->get : Symbol(BB.get, Decl(templateLiteralTypesPatterns.ts, 195, 26)) ->id : Symbol(id, Decl(templateLiteralTypesPatterns.ts, 196, 17)) ->Id : Symbol(Id, Decl(templateLiteralTypesPatterns.ts, 187, 1)) ->AA : Symbol(AA, Decl(templateLiteralTypesPatterns.ts, 191, 66)) +>get : Symbol(BB.get, Decl(templateLiteralTypesPatterns.ts, 198, 26)) +>id : Symbol(id, Decl(templateLiteralTypesPatterns.ts, 199, 17)) +>Id : Symbol(Id, Decl(templateLiteralTypesPatterns.ts, 190, 1)) +>AA : Symbol(AA, Decl(templateLiteralTypesPatterns.ts, 194, 66)) update(id: Id): void { ->update : Symbol(BB.update, Decl(templateLiteralTypesPatterns.ts, 196, 35)) ->id : Symbol(id, Decl(templateLiteralTypesPatterns.ts, 197, 11)) ->Id : Symbol(Id, Decl(templateLiteralTypesPatterns.ts, 187, 1)) ->AA : Symbol(AA, Decl(templateLiteralTypesPatterns.ts, 191, 66)) +>update : Symbol(BB.update, Decl(templateLiteralTypesPatterns.ts, 199, 35)) +>id : Symbol(id, Decl(templateLiteralTypesPatterns.ts, 200, 11)) +>Id : Symbol(Id, Decl(templateLiteralTypesPatterns.ts, 190, 1)) +>AA : Symbol(AA, Decl(templateLiteralTypesPatterns.ts, 194, 66)) this.get(id!); ->this.get : Symbol(BB.get, Decl(templateLiteralTypesPatterns.ts, 195, 26)) ->this : Symbol(BB, Decl(templateLiteralTypesPatterns.ts, 193, 18)) ->get : Symbol(BB.get, Decl(templateLiteralTypesPatterns.ts, 195, 26)) ->id : Symbol(id, Decl(templateLiteralTypesPatterns.ts, 197, 11)) +>this.get : Symbol(BB.get, Decl(templateLiteralTypesPatterns.ts, 198, 26)) +>this : Symbol(BB, Decl(templateLiteralTypesPatterns.ts, 196, 18)) +>get : Symbol(BB.get, Decl(templateLiteralTypesPatterns.ts, 198, 26)) +>id : Symbol(id, Decl(templateLiteralTypesPatterns.ts, 200, 11)) } } // repro from https://github.com/microsoft/TypeScript/issues/54177#issuecomment-1538436654 function conversionTest(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${string & {}}Downcast`) {} ->conversionTest : Symbol(conversionTest, Decl(templateLiteralTypesPatterns.ts, 200, 1)) ->groupName : Symbol(groupName, Decl(templateLiteralTypesPatterns.ts, 203, 24)) +>conversionTest : Symbol(conversionTest, Decl(templateLiteralTypesPatterns.ts, 203, 1)) +>groupName : Symbol(groupName, Decl(templateLiteralTypesPatterns.ts, 206, 24)) conversionTest("testDowncast"); ->conversionTest : Symbol(conversionTest, Decl(templateLiteralTypesPatterns.ts, 200, 1)) +>conversionTest : Symbol(conversionTest, Decl(templateLiteralTypesPatterns.ts, 203, 1)) function conversionTest2(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | `${{} & string}Downcast`) {} ->conversionTest2 : Symbol(conversionTest2, Decl(templateLiteralTypesPatterns.ts, 204, 31)) ->groupName : Symbol(groupName, Decl(templateLiteralTypesPatterns.ts, 205, 25)) +>conversionTest2 : Symbol(conversionTest2, Decl(templateLiteralTypesPatterns.ts, 207, 31)) +>groupName : Symbol(groupName, Decl(templateLiteralTypesPatterns.ts, 208, 25)) conversionTest2("testDowncast"); ->conversionTest2 : Symbol(conversionTest2, Decl(templateLiteralTypesPatterns.ts, 204, 31)) +>conversionTest2 : Symbol(conversionTest2, Decl(templateLiteralTypesPatterns.ts, 207, 31)) function foo(str: `${`a${string}` & `${string}a`}Test`) {} ->foo : Symbol(foo, Decl(templateLiteralTypesPatterns.ts, 206, 32)) ->str : Symbol(str, Decl(templateLiteralTypesPatterns.ts, 208, 13)) +>foo : Symbol(foo, Decl(templateLiteralTypesPatterns.ts, 209, 32)) +>str : Symbol(str, Decl(templateLiteralTypesPatterns.ts, 211, 13)) foo("abaTest"); // ok ->foo : Symbol(foo, Decl(templateLiteralTypesPatterns.ts, 206, 32)) +>foo : Symbol(foo, Decl(templateLiteralTypesPatterns.ts, 209, 32)) foo("abcTest"); // error ->foo : Symbol(foo, Decl(templateLiteralTypesPatterns.ts, 206, 32)) +>foo : Symbol(foo, Decl(templateLiteralTypesPatterns.ts, 209, 32)) diff --git a/tests/baselines/reference/templateLiteralTypesPatterns.types b/tests/baselines/reference/templateLiteralTypesPatterns.types index d9fbfeec9d8b2..da5401a0eddfb 100644 --- a/tests/baselines/reference/templateLiteralTypesPatterns.types +++ b/tests/baselines/reference/templateLiteralTypesPatterns.types @@ -560,14 +560,35 @@ var aa: '0' & `${number}`; // Remove string literals from unions with matching template literals -let t1: `foo${string}` | 'foo1' | '1foo'; // `foo${string}` | '1foo' ->t1 : `foo${string}` | "1foo" +declare let t1: `foo${string}` | 'foo1' | '1foo'; +>t1 : `foo${string}` | "foo1" | "1foo" -let t2: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo'; // `foo${string}` | '1foo' | 'xfoo' ->t2 : `foo${string}` | "1foo" | "xfoo" +let c1 = true ? t1 : t1; // `foo${string}` | '1foo' +>c1 : `foo${string}` | "1foo" +>true ? t1 : t1 : `foo${string}` | "1foo" +>true : true +>t1 : `foo${string}` | "foo1" | "1foo" +>t1 : `foo${string}` | "foo1" | "1foo" + +declare let t2: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo'; +>t2 : `foo${string}` | "foo1" | "1foo" | "foofoo" | "foox" | "xfoo" + +let c2 = true ? t2 : t2; // `foo${string}` | '1foo' | 'xfoo' +>c2 : `foo${string}` | "1foo" | "xfoo" +>true ? t2 : t2 : `foo${string}` | "1foo" | "xfoo" +>true : true +>t2 : `foo${string}` | "foo1" | "1foo" | "foofoo" | "foox" | "xfoo" +>t2 : `foo${string}` | "foo1" | "1foo" | "foofoo" | "foox" | "xfoo" + +declare let t3: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo' | `${number}foo`; +>t3 : `foo${string}` | "foo1" | "1foo" | "foofoo" | "foox" | "xfoo" | `${number}foo` -let t3: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo' | `${number}foo`; // `foo${string}` | xfoo' | `${number}foo` ->t3 : `foo${string}` | "xfoo" | `${number}foo` +let c3 = true ? t3 : t3; // `foo${string}` | xfoo' | `${number}foo` +>c3 : `foo${string}` | "xfoo" | `${number}foo` +>true ? t3 : t3 : `foo${string}` | "xfoo" | `${number}foo` +>true : true +>t3 : `foo${string}` | "foo1" | "1foo" | "foofoo" | "foox" | "xfoo" | `${number}foo` +>t3 : `foo${string}` | "foo1" | "1foo" | "foofoo" | "foox" | "xfoo" | `${number}foo` var bb: `${number}`; >bb : `${number}` diff --git a/tests/cases/conformance/types/literal/templateLiteralTypesPatterns.ts b/tests/cases/conformance/types/literal/templateLiteralTypesPatterns.ts index aeb05ead7ccca..70479f754996f 100644 --- a/tests/cases/conformance/types/literal/templateLiteralTypesPatterns.ts +++ b/tests/cases/conformance/types/literal/templateLiteralTypesPatterns.ts @@ -168,9 +168,12 @@ var aa: '0' & `${number}`; // Remove string literals from unions with matching template literals -let t1: `foo${string}` | 'foo1' | '1foo'; // `foo${string}` | '1foo' -let t2: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo'; // `foo${string}` | '1foo' | 'xfoo' -let t3: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo' | `${number}foo`; // `foo${string}` | xfoo' | `${number}foo` +declare let t1: `foo${string}` | 'foo1' | '1foo'; +let c1 = true ? t1 : t1; // `foo${string}` | '1foo' +declare let t2: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo'; +let c2 = true ? t2 : t2; // `foo${string}` | '1foo' | 'xfoo' +declare let t3: `foo1` | '1foo' | 'foofoo' | `foo${string}` | 'foox' | 'xfoo' | `${number}foo`; +let c3 = true ? t3 : t3; // `foo${string}` | xfoo' | `${number}foo` var bb: `${number}`; var bb: `${number}` | '0';