mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Reduce template literal types with a single placeholder and no extra texts (#55371)
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user