mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-21 08:25:43 -05:00
Template literal types for contextually typed template literal expressions (#43376)
* Template literal types for contextually typed template literal expressions * Accept new baselines * Add regression test * Add a few more tests
This commit is contained in:
@@ -31824,7 +31824,12 @@ namespace ts {
|
||||
texts.push(span.literal.text);
|
||||
types.push(isTypeAssignableTo(type, templateConstraintType) ? type : stringType);
|
||||
}
|
||||
return isConstContext(node) ? getTemplateLiteralType(texts, types) : stringType;
|
||||
return isConstContext(node) || someType(getContextualType(node) || unknownType, isTemplateLiteralContextualType) ? getTemplateLiteralType(texts, types) : stringType;
|
||||
}
|
||||
|
||||
function isTemplateLiteralContextualType(type: Type): boolean {
|
||||
return !!(type.flags & (TypeFlags.StringLiteral | TypeFlags.TemplateLiteral) ||
|
||||
type.flags & TypeFlags.InstantiableNonPrimitive && maybeTypeOfKind(getBaseConstraintOfType(type) || unknownType, TypeFlags.StringLike));
|
||||
}
|
||||
|
||||
function getContextNode(node: Expression): Node {
|
||||
|
||||
Reference in New Issue
Block a user