mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-26 20:14:05 -05:00
Reapply contextual type when recalculating array literals as tuples (#37071)
This commit is contained in:
@@ -14457,11 +14457,20 @@ namespace ts {
|
||||
return elaborateElementwise(generateLimitedTupleElements(node, target), source, target, relation, containingMessageChain, errorOutputContainer);
|
||||
}
|
||||
// recreate a tuple from the elements, if possible
|
||||
const tupleizedType = checkArrayLiteral(node, CheckMode.Contextual, /*forceTuple*/ true);
|
||||
if (isTupleLikeType(tupleizedType)) {
|
||||
return elaborateElementwise(generateLimitedTupleElements(node, target), tupleizedType, target, relation, containingMessageChain, errorOutputContainer);
|
||||
// Since we're re-doing the expression type, we need to reapply the contextual type
|
||||
const oldContext = node.contextualType;
|
||||
node.contextualType = target;
|
||||
try {
|
||||
const tupleizedType = checkArrayLiteral(node, CheckMode.Contextual, /*forceTuple*/ true);
|
||||
node.contextualType = oldContext;
|
||||
if (isTupleLikeType(tupleizedType)) {
|
||||
return elaborateElementwise(generateLimitedTupleElements(node, target), tupleizedType, target, relation, containingMessageChain, errorOutputContainer);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
node.contextualType = oldContext;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function *generateObjectLiteralElements(node: ObjectLiteralExpression): ElaborationIterator {
|
||||
|
||||
Reference in New Issue
Block a user