Skip to content

Commit 38d16bb

Browse files
committed
Improve handling of ++ and -- in control flow analysis
1 parent 7980489 commit 38d16bb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8426,8 +8426,11 @@ namespace ts {
84268426
// Assignments only narrow the computed type if the declared type is a union type. Thus, we
84278427
// only need to evaluate the assigned type if the declared type is a union type.
84288428
if (isMatchingReference(reference, node)) {
8429-
const isIncrementOrDecrement = node.parent.kind === SyntaxKind.PrefixUnaryExpression || node.parent.kind === SyntaxKind.PostfixUnaryExpression;
8430-
return declaredType.flags & TypeFlags.Union && !isIncrementOrDecrement ?
8429+
if (node.parent.kind === SyntaxKind.PrefixUnaryExpression || node.parent.kind === SyntaxKind.PostfixUnaryExpression) {
8430+
const flowType = getTypeAtFlowNode(flow.antecedent);
8431+
return createFlowType(getBaseTypeOfLiteralType(getTypeFromFlowType(flowType)), isIncomplete(flowType));
8432+
}
8433+
return declaredType.flags & TypeFlags.Union ?
84318434
getAssignmentReducedType(<UnionType>declaredType, getInitialOrAssignedType(node)) :
84328435
declaredType;
84338436
}

0 commit comments

Comments
 (0)