Fix crash caused by assertion with evolving array type (#38398)

* Properly finalize evolving array type in getTypeAtFlowCall

* Add regression test
This commit is contained in:
Anders Hejlsberg
2020-05-07 14:05:57 -07:00
committed by GitHub
parent f08863d2fc
commit 7798f532df
5 changed files with 89 additions and 1 deletions

View File

@@ -20360,7 +20360,7 @@ namespace ts {
const predicate = getTypePredicateOfSignature(signature);
if (predicate && (predicate.kind === TypePredicateKind.AssertsThis || predicate.kind === TypePredicateKind.AssertsIdentifier)) {
const flowType = getTypeAtFlowNode(flow.antecedent);
const type = getTypeFromFlowType(flowType);
const type = finalizeEvolvingArrayType(getTypeFromFlowType(flowType));
const narrowedType = predicate.type ? narrowTypeByTypePredicate(type, predicate, flow.node, /*assumeTrue*/ true) :
predicate.kind === TypePredicateKind.AssertsIdentifier && predicate.parameterIndex >= 0 && predicate.parameterIndex < flow.node.arguments.length ? narrowTypeByAssertion(type, flow.node.arguments[predicate.parameterIndex]) :
type;