mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-24 02:21:30 -05:00
fix(48034): Get a literal string of type intersection in a template literal type (#48044)
This commit is contained in:
@@ -15256,24 +15256,32 @@ namespace ts {
|
||||
}
|
||||
return type;
|
||||
|
||||
function addSpans(texts: readonly string[], types: readonly Type[]): boolean {
|
||||
function addSpans(texts: readonly string[] | string, types: readonly Type[]): boolean {
|
||||
const isTextsArray = isArray(texts);
|
||||
for (let i = 0; i < types.length; i++) {
|
||||
const t = types[i];
|
||||
const addText = isTextsArray ? texts[i + 1] : texts;
|
||||
if (t.flags & (TypeFlags.Literal | TypeFlags.Null | TypeFlags.Undefined)) {
|
||||
text += getTemplateStringForType(t) || "";
|
||||
text += texts[i + 1];
|
||||
text += addText;
|
||||
if (!isTextsArray) return true;
|
||||
}
|
||||
else if (t.flags & TypeFlags.TemplateLiteral) {
|
||||
text += (t as TemplateLiteralType).texts[0];
|
||||
if (!addSpans((t as TemplateLiteralType).texts, (t as TemplateLiteralType).types)) return false;
|
||||
text += texts[i + 1];
|
||||
text += addText;
|
||||
if (!isTextsArray) return true;
|
||||
}
|
||||
else if (isGenericIndexType(t) || isPatternLiteralPlaceholderType(t)) {
|
||||
newTypes.push(t);
|
||||
newTexts.push(text);
|
||||
text = texts[i + 1];
|
||||
text = addText;
|
||||
}
|
||||
else {
|
||||
else if (t.flags & TypeFlags.Intersection) {
|
||||
const added = addSpans(texts[i + 1], (t as IntersectionType).types);
|
||||
if (!added) return false;
|
||||
}
|
||||
else if (isTextsArray) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user