Skip to content

Commit b7d8809

Browse files
authored
Revert PR 55371 (#58702)
1 parent 5df3a10 commit b7d8809

11 files changed

Lines changed: 157 additions & 45 deletions

src/compiler/checker.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18087,16 +18087,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1808718087
if (contains(types, wildcardType)) {
1808818088
return wildcardType;
1808918089
}
18090-
if (
18091-
texts.length === 2 && texts[0] === "" && texts[1] === ""
18092-
// literals (including string enums) are stringified below
18093-
&& !(types[0].flags & TypeFlags.Literal)
18094-
// infer T extends StringLike can't be unwrapped eagerly
18095-
&& !types[0].symbol?.declarations?.some(d => d.parent.kind === SyntaxKind.InferType)
18096-
&& isTypeAssignableTo(types[0], stringType)
18097-
) {
18098-
return types[0];
18099-
}
1810018090
const newTypes: Type[] = [];
1810118091
const newTexts: string[] = [];
1810218092
let text = texts[0];

tests/baselines/reference/numericStringLiteralTypes.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ type T2 = string & `${bigint}`; // `${bigint}
1414
> : ^^^^^^^^^^^
1515

1616
type T3<T extends string> = string & `${T}`; // `${T}
17-
>T3 : T
18-
> : ^
17+
>T3 : `${T}`
18+
> : ^^^^^^
1919

2020
type T4<T extends string> = string & `${Capitalize<`${T}`>}`; // `${Capitalize<T>}`
21-
>T4 : Capitalize<T>
22-
> : ^^^^^^^^^^^^^
21+
>T4 : `${Capitalize<T>}`
22+
> : ^^^^^^^^^^^^^^^^^^
2323

2424
function f1(a: boolean[], x: `${number}`) {
2525
>f1 : (a: boolean[], x: `${number}`) => void

tests/baselines/reference/recursiveConditionalCrash3.types

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

tests/baselines/reference/recursiveConditionalCrash4.types

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//// [tests/cases/compiler/recursiveConditionalCrash4.ts] ////
22

3-
=== Performance Stats ===
4-
Instantiation count: 2,500
5-
63
=== recursiveConditionalCrash4.ts ===
74
// Repros from #53783
85

tests/baselines/reference/templateLiteralIntersection.types

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ type OriginA1 = `${A}`
2525
> : ^^^
2626

2727
type OriginA2 = `${MixA}`
28-
>OriginA2 : MixA
29-
> : ^^^^
28+
>OriginA2 : `${MixA}`
29+
> : ^^^^^^^^^
3030

3131
type B = `${typeof a}`
3232
>B : "a"
@@ -45,8 +45,8 @@ type OriginB1 = `${B}`
4545
> : ^^^
4646

4747
type OriginB2 = `${MixB}`
48-
>OriginB2 : MixB
49-
> : ^^^^
48+
>OriginB2 : `${MixB}`
49+
> : ^^^^^^^^^
5050

5151
type MixC = { foo: string } & A
5252
>MixC : MixC
@@ -55,20 +55,20 @@ type MixC = { foo: string } & A
5555
> : ^^^^^^
5656

5757
type OriginC = `${MixC}`
58-
>OriginC : MixC
59-
> : ^^^^
58+
>OriginC : `${MixC}`
59+
> : ^^^^^^^^^
6060

6161
type MixD<T extends string> =
62-
>MixD : T & { foo: string; }
63-
> : ^^^^^^^^^^^ ^^^
62+
>MixD : `${T & { foo: string; }}`
63+
> : ^^^^^^^^^^^^^^ ^^^^^
6464

6565
`${T & { foo: string }}`
6666
>foo : string
6767
> : ^^^^^^
6868

6969
type OriginD = `${MixD<A & { foo: string }> & { foo: string }}`;
70-
>OriginD : "a" & { foo: string; } & { foo: string; } & { foo: string; }
71-
> : ^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^
70+
>OriginD : `${`${"a" & { foo: string; } & { foo: string; }}` & { foo: string; }}`
71+
> : ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^
7272
>foo : string
7373
> : ^^^^^^
7474
>foo : string

tests/baselines/reference/templateLiteralIntersection3.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ options1[`foo/${path}`] = false;
4747

4848
// Lowercase<`foo/${Path}`> => `foo/${Lowercase<Path>}`
4949
declare const lowercasePath: Lowercase<`foo/${Path}`>;
50-
>lowercasePath : `foo/${Lowercase<Path>}`
51-
> : ^^^^^^^^^^^^^^^^^^^^^^^^
50+
>lowercasePath : `foo/${Lowercase<`${Path}`>}`
51+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5252

5353
options1[lowercasePath] = false;
5454
>options1[lowercasePath] = false : false
@@ -57,8 +57,8 @@ options1[lowercasePath] = false;
5757
> : ^^^^^^^
5858
>options1 : { prop: number; } & { [k: string]: boolean; }
5959
> : ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60-
>lowercasePath : `foo/${Lowercase<Path>}`
61-
> : ^^^^^^^^^^^^^^^^^^^^^^^^
60+
>lowercasePath : `foo/${Lowercase<`${Path}`>}`
61+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6262
>false : false
6363
> : ^^^^^
6464

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
templateLiteralTypes5.ts(10,7): error TS2322: Type '<T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0]' is not assignable to type 'F2'.
2+
Type 'TypeMap[T2]' is not assignable to type 'TypeMap[`${T2}`]'.
3+
Type 'T2' is not assignable to type '`${T2}`'.
4+
Type '"a" | "b"' is not assignable to type '`${T2}`'.
5+
Type '"a"' is not assignable to type '`${T2}`'.
6+
templateLiteralTypes5.ts(13,11): error TS2322: Type 'T3' is not assignable to type '`${T3}`'.
7+
Type '"a" | "b"' is not assignable to type '`${T3}`'.
8+
Type '"a"' is not assignable to type '`${T3}`'.
9+
templateLiteralTypes5.ts(14,11): error TS2322: Type '`${T3}`' is not assignable to type 'T3'.
10+
'`${T3}`' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'.
11+
Type '"a" | "b"' is not assignable to type 'T3'.
12+
'"a" | "b"' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'.
13+
Type '"a"' is not assignable to type 'T3'.
14+
'"a"' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'.
15+
16+
17+
==== templateLiteralTypes5.ts (3 errors) ====
18+
// https://github.com/microsoft/TypeScript/issues/55364
19+
interface TypeMap {
20+
a: "A";
21+
b: "B";
22+
}
23+
declare const f: <T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0];
24+
type F1 = <T1 extends "a" | "b">(x: `${T1}`) => TypeMap[T1];
25+
const f1: F1 = f;
26+
type F2 = <T2 extends 'a' | 'b'>(x: `${T2}`) => TypeMap[`${T2}`]
27+
const f2: F2 = f
28+
~~
29+
!!! error TS2322: Type '<T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0]' is not assignable to type 'F2'.
30+
!!! error TS2322: Type 'TypeMap[T2]' is not assignable to type 'TypeMap[`${T2}`]'.
31+
!!! error TS2322: Type 'T2' is not assignable to type '`${T2}`'.
32+
!!! error TS2322: Type '"a" | "b"' is not assignable to type '`${T2}`'.
33+
!!! error TS2322: Type '"a"' is not assignable to type '`${T2}`'.
34+
35+
function f3<T3 extends "a" | "b">(x: T3) {
36+
const test1: `${T3}` = x
37+
~~~~~
38+
!!! error TS2322: Type 'T3' is not assignable to type '`${T3}`'.
39+
!!! error TS2322: Type '"a" | "b"' is not assignable to type '`${T3}`'.
40+
!!! error TS2322: Type '"a"' is not assignable to type '`${T3}`'.
41+
const test2: T3 = "" as `${T3}`;
42+
~~~~~
43+
!!! error TS2322: Type '`${T3}`' is not assignable to type 'T3'.
44+
!!! error TS2322: '`${T3}`' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'.
45+
!!! error TS2322: Type '"a" | "b"' is not assignable to type 'T3'.
46+
!!! error TS2322: '"a" | "b"' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'.
47+
!!! error TS2322: Type '"a"' is not assignable to type 'T3'.
48+
!!! error TS2322: '"a"' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'.
49+
}
50+

tests/baselines/reference/templateLiteralTypes5.types

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ interface TypeMap {
1414
declare const f: <T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0];
1515
>f : <T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0]
1616
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
17-
>x : T0
18-
> : ^^
17+
>x : `${T0}`
18+
> : ^^^^^^^
1919

2020
type F1 = <T1 extends "a" | "b">(x: `${T1}`) => TypeMap[T1];
2121
>F1 : F1
2222
> : ^^
23-
>x : T1
24-
> : ^^
23+
>x : `${T1}`
24+
> : ^^^^^^^
2525

2626
const f1: F1 = f;
2727
>f1 : F1
@@ -32,8 +32,8 @@ const f1: F1 = f;
3232
type F2 = <T2 extends 'a' | 'b'>(x: `${T2}`) => TypeMap[`${T2}`]
3333
>F2 : F2
3434
> : ^^
35-
>x : T2
36-
> : ^^
35+
>x : `${T2}`
36+
> : ^^^^^^^
3737

3838
const f2: F2 = f
3939
>f2 : F2
@@ -48,16 +48,16 @@ function f3<T3 extends "a" | "b">(x: T3) {
4848
> : ^^
4949

5050
const test1: `${T3}` = x
51-
>test1 : T3
52-
> : ^^
51+
>test1 : `${T3}`
52+
> : ^^^^^^^
5353
>x : T3
5454
> : ^^
5555

5656
const test2: T3 = "" as `${T3}`;
5757
>test2 : T3
5858
> : ^^
59-
>"" as `${T3}` : T3
60-
> : ^^
59+
>"" as `${T3}` : `${T3}`
60+
> : ^^^^^^^
6161
>"" : ""
6262
> : ^^
6363
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [tests/cases/conformance/types/literal/templateLiteralTypes8.ts] ////
2+
3+
=== templateLiteralTypes8.ts ===
4+
const enum E {
5+
>E : Symbol(E, Decl(templateLiteralTypes8.ts, 0, 0))
6+
7+
a = "a",
8+
>a : Symbol(E.a, Decl(templateLiteralTypes8.ts, 0, 14))
9+
10+
b = "b",
11+
>b : Symbol(E.b, Decl(templateLiteralTypes8.ts, 1, 10))
12+
}
13+
14+
type Stringify<T extends string> = `${T}`;
15+
>Stringify : Symbol(Stringify, Decl(templateLiteralTypes8.ts, 3, 1))
16+
>T : Symbol(T, Decl(templateLiteralTypes8.ts, 5, 15))
17+
>T : Symbol(T, Decl(templateLiteralTypes8.ts, 5, 15))
18+
19+
let z1: `${E}` = "a";
20+
>z1 : Symbol(z1, Decl(templateLiteralTypes8.ts, 7, 3))
21+
>E : Symbol(E, Decl(templateLiteralTypes8.ts, 0, 0))
22+
23+
let z2: Stringify<E> = "a";
24+
>z2 : Symbol(z2, Decl(templateLiteralTypes8.ts, 8, 3))
25+
>Stringify : Symbol(Stringify, Decl(templateLiteralTypes8.ts, 3, 1))
26+
>E : Symbol(E, Decl(templateLiteralTypes8.ts, 0, 0))
27+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//// [tests/cases/conformance/types/literal/templateLiteralTypes8.ts] ////
2+
3+
=== templateLiteralTypes8.ts ===
4+
const enum E {
5+
>E : E
6+
> : ^
7+
8+
a = "a",
9+
>a : E.a
10+
> : ^^^
11+
>"a" : "a"
12+
> : ^^^
13+
14+
b = "b",
15+
>b : E.b
16+
> : ^^^
17+
>"b" : "b"
18+
> : ^^^
19+
}
20+
21+
type Stringify<T extends string> = `${T}`;
22+
>Stringify : `${T}`
23+
> : ^^^^^^
24+
25+
let z1: `${E}` = "a";
26+
>z1 : "a" | "b"
27+
> : ^^^^^^^^^
28+
>"a" : "a"
29+
> : ^^^
30+
31+
let z2: Stringify<E> = "a";
32+
>z2 : "a" | "b"
33+
> : ^^^^^^^^^
34+
>"a" : "a"
35+
> : ^^^
36+

0 commit comments

Comments
 (0)