Reapply contextual type when recalculating array literals as tuples (#37071)

This commit is contained in:
Wesley Wigham
2020-02-27 14:02:28 -08:00
committed by GitHub
parent e71614a185
commit e7c578a67d
6 changed files with 186 additions and 4 deletions

View File

@@ -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 {