Revert PR 55371 (#58702)

This commit is contained in:
Gabriela Araujo Britto
2024-05-30 09:53:58 -07:00
committed by GitHub
parent 5df3a107c0
commit b7d8809150
11 changed files with 157 additions and 45 deletions

View File

@@ -18087,16 +18087,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (contains(types, wildcardType)) {
return wildcardType;
}
if (
texts.length === 2 && texts[0] === "" && texts[1] === ""
// literals (including string enums) are stringified below
&& !(types[0].flags & TypeFlags.Literal)
// infer T extends StringLike can't be unwrapped eagerly
&& !types[0].symbol?.declarations?.some(d => d.parent.kind === SyntaxKind.InferType)
&& isTypeAssignableTo(types[0], stringType)
) {
return types[0];
}
const newTypes: Type[] = [];
const newTexts: string[] = [];
let text = texts[0];

View File

@@ -14,12 +14,12 @@ type T2 = string & `${bigint}`; // `${bigint}
> : ^^^^^^^^^^^
type T3<T extends string> = string & `${T}`; // `${T}
>T3 : T
> : ^
>T3 : `${T}`
> : ^^^^^^
type T4<T extends string> = string & `${Capitalize<`${T}`>}`; // `${Capitalize<T>}`
>T4 : Capitalize<T>
> : ^^^^^^^^^^^^^
>T4 : `${Capitalize<T>}`
> : ^^^^^^^^^^^^^^^^^^
function f1(a: boolean[], x: `${number}`) {
>f1 : (a: boolean[], x: `${number}`) => void

File diff suppressed because one or more lines are too long

View File

@@ -1,8 +1,5 @@
//// [tests/cases/compiler/recursiveConditionalCrash4.ts] ////
=== Performance Stats ===
Instantiation count: 2,500
=== recursiveConditionalCrash4.ts ===
// Repros from #53783

View File

@@ -25,8 +25,8 @@ type OriginA1 = `${A}`
> : ^^^
type OriginA2 = `${MixA}`
>OriginA2 : MixA
> : ^^^^
>OriginA2 : `${MixA}`
> : ^^^^^^^^^
type B = `${typeof a}`
>B : "a"
@@ -45,8 +45,8 @@ type OriginB1 = `${B}`
> : ^^^
type OriginB2 = `${MixB}`
>OriginB2 : MixB
> : ^^^^
>OriginB2 : `${MixB}`
> : ^^^^^^^^^
type MixC = { foo: string } & A
>MixC : MixC
@@ -55,20 +55,20 @@ type MixC = { foo: string } & A
> : ^^^^^^
type OriginC = `${MixC}`
>OriginC : MixC
> : ^^^^
>OriginC : `${MixC}`
> : ^^^^^^^^^
type MixD<T extends string> =
>MixD : T & { foo: string; }
> : ^^^^^^^^^^^ ^^^
>MixD : `${T & { foo: string; }}`
> : ^^^^^^^^^^^^^^ ^^^^^
`${T & { foo: string }}`
>foo : string
> : ^^^^^^
type OriginD = `${MixD<A & { foo: string }> & { foo: string }}`;
>OriginD : "a" & { foo: string; } & { foo: string; } & { foo: string; }
> : ^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^
>OriginD : `${`${"a" & { foo: string; } & { foo: string; }}` & { foo: string; }}`
> : ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^
>foo : string
> : ^^^^^^
>foo : string

View File

@@ -47,8 +47,8 @@ options1[`foo/${path}`] = false;
// Lowercase<`foo/${Path}`> => `foo/${Lowercase<Path>}`
declare const lowercasePath: Lowercase<`foo/${Path}`>;
>lowercasePath : `foo/${Lowercase<Path>}`
> : ^^^^^^^^^^^^^^^^^^^^^^^^
>lowercasePath : `foo/${Lowercase<`${Path}`>}`
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
options1[lowercasePath] = false;
>options1[lowercasePath] = false : false
@@ -57,8 +57,8 @@ options1[lowercasePath] = false;
> : ^^^^^^^
>options1 : { prop: number; } & { [k: string]: boolean; }
> : ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>lowercasePath : `foo/${Lowercase<Path>}`
> : ^^^^^^^^^^^^^^^^^^^^^^^^
>lowercasePath : `foo/${Lowercase<`${Path}`>}`
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>false : false
> : ^^^^^

View File

@@ -0,0 +1,50 @@
templateLiteralTypes5.ts(10,7): error TS2322: Type '<T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0]' is not assignable to type 'F2'.
Type 'TypeMap[T2]' is not assignable to type 'TypeMap[`${T2}`]'.
Type 'T2' is not assignable to type '`${T2}`'.
Type '"a" | "b"' is not assignable to type '`${T2}`'.
Type '"a"' is not assignable to type '`${T2}`'.
templateLiteralTypes5.ts(13,11): error TS2322: Type 'T3' is not assignable to type '`${T3}`'.
Type '"a" | "b"' is not assignable to type '`${T3}`'.
Type '"a"' is not assignable to type '`${T3}`'.
templateLiteralTypes5.ts(14,11): error TS2322: Type '`${T3}`' is not assignable to type 'T3'.
'`${T3}`' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'.
Type '"a" | "b"' is not assignable to type 'T3'.
'"a" | "b"' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'.
Type '"a"' is not assignable to type 'T3'.
'"a"' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'.
==== templateLiteralTypes5.ts (3 errors) ====
// https://github.com/microsoft/TypeScript/issues/55364
interface TypeMap {
a: "A";
b: "B";
}
declare const f: <T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0];
type F1 = <T1 extends "a" | "b">(x: `${T1}`) => TypeMap[T1];
const f1: F1 = f;
type F2 = <T2 extends 'a' | 'b'>(x: `${T2}`) => TypeMap[`${T2}`]
const f2: F2 = f
~~
!!! error TS2322: Type '<T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0]' is not assignable to type 'F2'.
!!! error TS2322: Type 'TypeMap[T2]' is not assignable to type 'TypeMap[`${T2}`]'.
!!! error TS2322: Type 'T2' is not assignable to type '`${T2}`'.
!!! error TS2322: Type '"a" | "b"' is not assignable to type '`${T2}`'.
!!! error TS2322: Type '"a"' is not assignable to type '`${T2}`'.
function f3<T3 extends "a" | "b">(x: T3) {
const test1: `${T3}` = x
~~~~~
!!! error TS2322: Type 'T3' is not assignable to type '`${T3}`'.
!!! error TS2322: Type '"a" | "b"' is not assignable to type '`${T3}`'.
!!! error TS2322: Type '"a"' is not assignable to type '`${T3}`'.
const test2: T3 = "" as `${T3}`;
~~~~~
!!! error TS2322: Type '`${T3}`' is not assignable to type 'T3'.
!!! error TS2322: '`${T3}`' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'.
!!! error TS2322: Type '"a" | "b"' is not assignable to type 'T3'.
!!! 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"'.
!!! error TS2322: Type '"a"' is not assignable to type 'T3'.
!!! error TS2322: '"a"' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'.
}

View File

@@ -14,14 +14,14 @@ interface TypeMap {
declare const f: <T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0];
>f : <T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0]
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
>x : T0
> : ^^
>x : `${T0}`
> : ^^^^^^^
type F1 = <T1 extends "a" | "b">(x: `${T1}`) => TypeMap[T1];
>F1 : F1
> : ^^
>x : T1
> : ^^
>x : `${T1}`
> : ^^^^^^^
const f1: F1 = f;
>f1 : F1
@@ -32,8 +32,8 @@ const f1: F1 = f;
type F2 = <T2 extends 'a' | 'b'>(x: `${T2}`) => TypeMap[`${T2}`]
>F2 : F2
> : ^^
>x : T2
> : ^^
>x : `${T2}`
> : ^^^^^^^
const f2: F2 = f
>f2 : F2
@@ -48,16 +48,16 @@ function f3<T3 extends "a" | "b">(x: T3) {
> : ^^
const test1: `${T3}` = x
>test1 : T3
> : ^^
>test1 : `${T3}`
> : ^^^^^^^
>x : T3
> : ^^
const test2: T3 = "" as `${T3}`;
>test2 : T3
> : ^^
>"" as `${T3}` : T3
> : ^^
>"" as `${T3}` : `${T3}`
> : ^^^^^^^
>"" : ""
> : ^^
}

View File

@@ -0,0 +1,27 @@
//// [tests/cases/conformance/types/literal/templateLiteralTypes8.ts] ////
=== templateLiteralTypes8.ts ===
const enum E {
>E : Symbol(E, Decl(templateLiteralTypes8.ts, 0, 0))
a = "a",
>a : Symbol(E.a, Decl(templateLiteralTypes8.ts, 0, 14))
b = "b",
>b : Symbol(E.b, Decl(templateLiteralTypes8.ts, 1, 10))
}
type Stringify<T extends string> = `${T}`;
>Stringify : Symbol(Stringify, Decl(templateLiteralTypes8.ts, 3, 1))
>T : Symbol(T, Decl(templateLiteralTypes8.ts, 5, 15))
>T : Symbol(T, Decl(templateLiteralTypes8.ts, 5, 15))
let z1: `${E}` = "a";
>z1 : Symbol(z1, Decl(templateLiteralTypes8.ts, 7, 3))
>E : Symbol(E, Decl(templateLiteralTypes8.ts, 0, 0))
let z2: Stringify<E> = "a";
>z2 : Symbol(z2, Decl(templateLiteralTypes8.ts, 8, 3))
>Stringify : Symbol(Stringify, Decl(templateLiteralTypes8.ts, 3, 1))
>E : Symbol(E, Decl(templateLiteralTypes8.ts, 0, 0))

View File

@@ -0,0 +1,36 @@
//// [tests/cases/conformance/types/literal/templateLiteralTypes8.ts] ////
=== templateLiteralTypes8.ts ===
const enum E {
>E : E
> : ^
a = "a",
>a : E.a
> : ^^^
>"a" : "a"
> : ^^^
b = "b",
>b : E.b
> : ^^^
>"b" : "b"
> : ^^^
}
type Stringify<T extends string> = `${T}`;
>Stringify : `${T}`
> : ^^^^^^
let z1: `${E}` = "a";
>z1 : "a" | "b"
> : ^^^^^^^^^
>"a" : "a"
> : ^^^
let z2: Stringify<E> = "a";
>z2 : "a" | "b"
> : ^^^^^^^^^
>"a" : "a"
> : ^^^

View File

@@ -0,0 +1,12 @@
// @strict: true
// @noEmit: true
const enum E {
a = "a",
b = "b",
}
type Stringify<T extends string> = `${T}`;
let z1: `${E}` = "a";
let z2: Stringify<E> = "a";