diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7a8127a2689..56a36f658d7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20763,7 +20763,7 @@ namespace ts { function getBaseTypeOfLiteralType(type: Type): Type { return type.flags & TypeFlags.EnumLiteral ? getBaseTypeOfEnumLiteralType(type as LiteralType) : - type.flags & TypeFlags.StringLiteral ? stringType : + type.flags & (TypeFlags.StringLiteral | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) ? stringType : type.flags & TypeFlags.NumberLiteral ? numberType : type.flags & TypeFlags.BigIntLiteral ? bigintType : type.flags & TypeFlags.BooleanLiteral ? booleanType : diff --git a/tests/baselines/reference/templateLiteralTypes3.errors.txt b/tests/baselines/reference/templateLiteralTypes3.errors.txt index 4c6e98d9365..d9e2608ac88 100644 --- a/tests/baselines/reference/templateLiteralTypes3.errors.txt +++ b/tests/baselines/reference/templateLiteralTypes3.errors.txt @@ -198,4 +198,23 @@ tests/cases/conformance/types/literal/templateLiteralTypes3.ts(141,9): error TS2 action.response; } } + + // Repro from #46768 + + type DotString = `${string}.${string}.${string}`; + + declare function noSpread
(args: P[]): P; + declare function spread
(...args: P[]): P;
+
+ noSpread([`1.${'2'}.3`, `1.${'2'}.4`]);
+ noSpread([`1.${'2' as string}.3`, `1.${'2' as string}.4`]);
+
+ spread(`1.${'2'}.3`, `1.${'2'}.4`);
+ spread(`1.${'2' as string}.3`, `1.${'2' as string}.4`);
+
+ function ft1 (args: P[]): P;
+declare function spread (...args: P[]): P;
+
+noSpread([`1.${'2'}.3`, `1.${'2'}.4`]);
+noSpread([`1.${'2' as string}.3`, `1.${'2' as string}.4`]);
+
+spread(`1.${'2'}.3`, `1.${'2'}.4`);
+spread(`1.${'2' as string}.3`, `1.${'2' as string}.4`);
+
+function ft1 (args: P[]): P;
+declare function spread (...args: P[]): P;
+declare function ft1 (args: P[]): P;
+>noSpread : Symbol(noSpread, Decl(templateLiteralTypes3.ts, 174, 49))
+>P : Symbol(P, Decl(templateLiteralTypes3.ts, 176, 26))
+>DotString : Symbol(DotString, Decl(templateLiteralTypes3.ts, 170, 1))
+>args : Symbol(args, Decl(templateLiteralTypes3.ts, 176, 47))
+>P : Symbol(P, Decl(templateLiteralTypes3.ts, 176, 26))
+>P : Symbol(P, Decl(templateLiteralTypes3.ts, 176, 26))
+
+declare function spread (...args: P[]): P;
+>spread : Symbol(spread, Decl(templateLiteralTypes3.ts, 176, 61))
+>P : Symbol(P, Decl(templateLiteralTypes3.ts, 177, 24))
+>DotString : Symbol(DotString, Decl(templateLiteralTypes3.ts, 170, 1))
+>args : Symbol(args, Decl(templateLiteralTypes3.ts, 177, 45))
+>P : Symbol(P, Decl(templateLiteralTypes3.ts, 177, 24))
+>P : Symbol(P, Decl(templateLiteralTypes3.ts, 177, 24))
+
+noSpread([`1.${'2'}.3`, `1.${'2'}.4`]);
+>noSpread : Symbol(noSpread, Decl(templateLiteralTypes3.ts, 174, 49))
+
+noSpread([`1.${'2' as string}.3`, `1.${'2' as string}.4`]);
+>noSpread : Symbol(noSpread, Decl(templateLiteralTypes3.ts, 174, 49))
+
+spread(`1.${'2'}.3`, `1.${'2'}.4`);
+>spread : Symbol(spread, Decl(templateLiteralTypes3.ts, 176, 61))
+
+spread(`1.${'2' as string}.3`, `1.${'2' as string}.4`);
+>spread : Symbol(spread, Decl(templateLiteralTypes3.ts, 176, 61))
+
+function ft1 (args: P[]): P;
+>noSpread : (args: P[]) => P
+>args : P[]
+
+declare function spread (...args: P[]): P;
+>spread : (...args: P[]) => P
+>args : P[]
+
+noSpread([`1.${'2'}.3`, `1.${'2'}.4`]);
+>noSpread([`1.${'2'}.3`, `1.${'2'}.4`]) : "1.2.3" | "1.2.4"
+>noSpread : (args: P[]) => P
+>[`1.${'2'}.3`, `1.${'2'}.4`] : ("1.2.3" | "1.2.4")[]
+>`1.${'2'}.3` : "1.2.3"
+>'2' : "2"
+>`1.${'2'}.4` : "1.2.4"
+>'2' : "2"
+
+noSpread([`1.${'2' as string}.3`, `1.${'2' as string}.4`]);
+>noSpread([`1.${'2' as string}.3`, `1.${'2' as string}.4`]) : `1.${string}.3` | `1.${string}.4`
+>noSpread : (args: P[]) => P
+>[`1.${'2' as string}.3`, `1.${'2' as string}.4`] : (`1.${string}.3` | `1.${string}.4`)[]
+>`1.${'2' as string}.3` : `1.${string}.3`
+>'2' as string : string
+>'2' : "2"
+>`1.${'2' as string}.4` : `1.${string}.4`
+>'2' as string : string
+>'2' : "2"
+
+spread(`1.${'2'}.3`, `1.${'2'}.4`);
+>spread(`1.${'2'}.3`, `1.${'2'}.4`) : "1.2.3" | "1.2.4"
+>spread : (...args: P[]) => P
+>`1.${'2'}.3` : "1.2.3"
+>'2' : "2"
+>`1.${'2'}.4` : "1.2.4"
+>'2' : "2"
+
+spread(`1.${'2' as string}.3`, `1.${'2' as string}.4`);
+>spread(`1.${'2' as string}.3`, `1.${'2' as string}.4`) : `1.${string}.3` | `1.${string}.4`
+>spread : (...args: P[]) => P
+>`1.${'2' as string}.3` : `1.${string}.3`
+>'2' as string : string
+>'2' : "2"
+>`1.${'2' as string}.4` : `1.${string}.4`
+>'2' as string : string
+>'2' : "2"
+
+function ft1 (...args: P[]) => P
+>`1.${t}.3` : `1.${T}.3`
+>t : T
+>`1.${t}.4` : `1.${T}.4`
+>t : T
+
+ spread(`1.${u}.3`, `1.${u}.4`);
+>spread(`1.${u}.3`, `1.${u}.4`) : `1.${Uppercase (...args: P[]) => P
+>`1.${u}.3` : `1.${Uppercase (...args: P[]) => P
+>u1 : Uppercase<`1.${T}.3`>
+>u2 : Uppercase<`1.${T}.4`>
+}
+
diff --git a/tests/cases/conformance/types/literal/templateLiteralTypes3.ts b/tests/cases/conformance/types/literal/templateLiteralTypes3.ts
index fbeae4b3f65..8c47fff8cb2 100644
--- a/tests/cases/conformance/types/literal/templateLiteralTypes3.ts
+++ b/tests/cases/conformance/types/literal/templateLiteralTypes3.ts
@@ -172,3 +172,22 @@ function reducer(action: Action) {
action.response;
}
}
+
+// Repro from #46768
+
+type DotString = `${string}.${string}.${string}`;
+
+declare function noSpread (args: P[]): P;
+declare function spread (...args: P[]): P;
+
+noSpread([`1.${'2'}.3`, `1.${'2'}.4`]);
+noSpread([`1.${'2' as string}.3`, `1.${'2' as string}.4`]);
+
+spread(`1.${'2'}.3`, `1.${'2'}.4`);
+spread(`1.${'2' as string}.3`, `1.${'2' as string}.4`);
+
+function ft1