Skip to content

Commit 8b1f1e5

Browse files
committed
Revert PR 48044
1 parent 1dd84d2 commit 8b1f1e5

File tree

4 files changed

+15
-51
lines changed

4 files changed

+15
-51
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16971,6 +16971,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1697116971
}
1697216972

1697316973
function getTemplateLiteralType(texts: readonly string[], types: readonly Type[]): Type {
16974+
// TODO(jakebailey): filter out intersections here?
1697416975
const unionIndex = findIndex(types, t => !!(t.flags & (TypeFlags.Never | TypeFlags.Union)));
1697516976
if (unionIndex >= 0) {
1697616977
return checkCrossProductUnion(types) ?
@@ -17006,32 +17007,24 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1700617007
}
1700717008
return type;
1700817009

17009-
function addSpans(texts: readonly string[] | string, types: readonly Type[]): boolean {
17010-
const isTextsArray = isArray(texts);
17010+
function addSpans(texts: readonly string[], types: readonly Type[]): boolean {
1701117011
for (let i = 0; i < types.length; i++) {
1701217012
const t = types[i];
17013-
const addText = isTextsArray ? texts[i + 1] : texts;
1701417013
if (t.flags & (TypeFlags.Literal | TypeFlags.Null | TypeFlags.Undefined)) {
1701517014
text += getTemplateStringForType(t) || "";
17016-
text += addText;
17017-
if (!isTextsArray) return true;
17015+
text += texts[i + 1];
1701817016
}
1701917017
else if (t.flags & TypeFlags.TemplateLiteral) {
1702017018
text += (t as TemplateLiteralType).texts[0];
1702117019
if (!addSpans((t as TemplateLiteralType).texts, (t as TemplateLiteralType).types)) return false;
17022-
text += addText;
17023-
if (!isTextsArray) return true;
17020+
text += texts[i + 1];
1702417021
}
1702517022
else if (isGenericIndexType(t) || isPatternLiteralPlaceholderType(t)) {
1702617023
newTypes.push(t);
1702717024
newTexts.push(text);
17028-
text = addText;
17025+
text = texts[i + 1];
1702917026
}
17030-
else if (t.flags & TypeFlags.Intersection) {
17031-
const added = addSpans(texts[i + 1], (t as IntersectionType).types);
17032-
if (!added) return false;
17033-
}
17034-
else if (isTextsArray) {
17027+
else {
1703517028
return false;
1703617029
}
1703717030
}

tests/baselines/reference/deeplyNestedTemplateLiteralIntersection.errors.txt

Lines changed: 0 additions & 29 deletions
This file was deleted.

tests/baselines/reference/templateLiteralIntersection.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type OriginA1 = `${A}`
1616
>OriginA1 : "a"
1717

1818
type OriginA2 = `${MixA}`
19-
>OriginA2 : "a"
19+
>OriginA2 : string
2020

2121
type B = `${typeof a}`
2222
>B : "a"
@@ -30,14 +30,14 @@ type OriginB1 = `${B}`
3030
>OriginB1 : "a"
3131

3232
type OriginB2 = `${MixB}`
33-
>OriginB2 : "a"
33+
>OriginB2 : string
3434

3535
type MixC = { foo: string } & A
3636
>MixC : { foo: string; } & "a"
3737
>foo : string
3838

3939
type OriginC = `${MixC}`
40-
>OriginC : "a"
40+
>OriginC : string
4141

4242
type MixD<T extends string> =
4343
>MixD : `${T & { foo: string; }}`
@@ -46,7 +46,7 @@ type MixD<T extends string> =
4646
>foo : string
4747

4848
type OriginD = `${MixD<A & { foo: string }> & { foo: string }}`;
49-
>OriginD : "a"
49+
>OriginD : string
5050
>foo : string
5151
>foo : string
5252

tests/baselines/reference/templateLiteralIntersection2.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ type Path = string & { _pathBrand: any };
44
>_pathBrand : any
55

66
type JoinedPath = `${Path}/${Path}`;
7-
>JoinedPath : `${string}/${string}`
7+
>JoinedPath : string
88

99
declare function joinedPath(p: JoinedPath): void;
1010
>joinedPath : (p: JoinedPath) => void
11-
>p : `${string}/${string}`
11+
>p : string
1212

1313
joinedPath("foo/bar");
1414
>joinedPath("foo/bar") : void
15-
>joinedPath : (p: `${string}/${string}`) => void
15+
>joinedPath : (p: string) => void
1616
>"foo/bar" : "foo/bar"
1717

1818
declare const somePath: Path;
1919
>somePath : Path
2020

2121
joinedPath(`${somePath}/${somePath}`);
2222
>joinedPath(`${somePath}/${somePath}`) : void
23-
>joinedPath : (p: `${string}/${string}`) => void
24-
>`${somePath}/${somePath}` : `${string}/${string}`
23+
>joinedPath : (p: string) => void
24+
>`${somePath}/${somePath}` : string
2525
>somePath : Path
2626
>somePath : Path
2727

0 commit comments

Comments
 (0)