Cherry-pick PR #38398 into release-3.9 (#38400)

Component commits:
99c5c096c5 Properly finalize evolving array type in getTypeAtFlowCall

b355cd4da4 Add regression test

Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
This commit is contained in:
TypeScript Bot
2020-05-07 23:50:20 -07:00
committed by GitHub
parent 8f79cd42f4
commit d906a471dd
5 changed files with 89 additions and 1 deletions

View File

@@ -20291,7 +20291,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;