From 38d16bb4be50c797e81d07cf931e5c09a92ee475 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 20 Sep 2016 13:22:43 -0700 Subject: [PATCH] Improve handling of ++ and -- in control flow analysis --- src/compiler/checker.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bef1b0bcb9b..aaa800a391e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8426,8 +8426,11 @@ namespace ts { // Assignments only narrow the computed type if the declared type is a union type. Thus, we // only need to evaluate the assigned type if the declared type is a union type. if (isMatchingReference(reference, node)) { - const isIncrementOrDecrement = node.parent.kind === SyntaxKind.PrefixUnaryExpression || node.parent.kind === SyntaxKind.PostfixUnaryExpression; - return declaredType.flags & TypeFlags.Union && !isIncrementOrDecrement ? + if (node.parent.kind === SyntaxKind.PrefixUnaryExpression || node.parent.kind === SyntaxKind.PostfixUnaryExpression) { + const flowType = getTypeAtFlowNode(flow.antecedent); + return createFlowType(getBaseTypeOfLiteralType(getTypeFromFlowType(flowType)), isIncomplete(flowType)); + } + return declaredType.flags & TypeFlags.Union ? getAssignmentReducedType(declaredType, getInitialOrAssignedType(node)) : declaredType; }