Remove object literal freshness in control flow based array types (#39518)

* Remove object literal freshness in control flow based array types

* Add regression test
This commit is contained in:
Anders Hejlsberg
2020-07-10 10:18:15 -07:00
committed by GitHub
parent 87a74aa9ce
commit c335aad665
5 changed files with 73 additions and 3 deletions

View File

@@ -20633,7 +20633,7 @@ namespace ts {
// we defer subtype reduction until the evolving array type is finalized into a manifest
// array type.
function addEvolvingArrayElementType(evolvingArrayType: EvolvingArrayType, node: Expression): EvolvingArrayType {
const elementType = getBaseTypeOfLiteralType(getContextFreeTypeOfExpression(node));
const elementType = getRegularTypeOfObjectLiteral(getBaseTypeOfLiteralType(getContextFreeTypeOfExpression(node)));
return isTypeSubsetOf(elementType, evolvingArrayType.elementType) ? evolvingArrayType : getEvolvingArrayType(getUnionType([evolvingArrayType.elementType, elementType]));
}