Match control flow logic for switch statements to conditional expressions

This commit is contained in:
Anders Hejlsberg
2019-01-24 09:30:36 -08:00
parent 3a2f6a3ed1
commit 9844436231

View File

@@ -15780,9 +15780,6 @@ namespace ts {
function getTypeAtSwitchClause(flow: FlowSwitchClause): FlowType {
const expr = flow.switchStatement.expression;
if (containsMatchingReferenceDiscriminant(reference, expr)) {
return declaredType;
}
const flowType = getTypeAtFlowNode(flow.antecedent);
let type = getTypeFromFlowType(flowType);
if (isMatchingReference(reference, expr)) {
@@ -15797,6 +15794,9 @@ namespace ts {
else if (expr.kind === SyntaxKind.TypeOfExpression && isMatchingReference(reference, (expr as TypeOfExpression).expression)) {
type = narrowBySwitchOnTypeOf(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd);
}
else if (containsMatchingReferenceDiscriminant(reference, expr)) {
type = declaredType;
}
return createFlowType(type, isIncomplete(flowType));
}