Reduce template literal types with a single placeholder and no extra texts (#55371)

This commit is contained in:
Mateusz Burzyński
2024-03-14 13:26:36 -07:00
committed by GitHub
parent d64646b3fd
commit a64ea3ae64
12 changed files with 289 additions and 13 deletions
+10
View File
@@ -17984,6 +17984,16 @@ 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];