Skip to content

Commit 6e72858

Browse files
committed
Assume outer variables are always initialized in control flow analysis
1 parent b052d69 commit 6e72858

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8920,6 +8920,7 @@ namespace ts {
89208920
const isParameter = getRootDeclaration(declaration).kind === SyntaxKind.Parameter;
89218921
const declarationContainer = getControlFlowContainer(declaration);
89228922
let flowContainer = getControlFlowContainer(node);
8923+
const isOuterVariable = flowContainer !== declarationContainer;
89238924
// When the control flow originates in a function expression or arrow function and we are referencing
89248925
// a const variable or parameter from an outer function, we extend the origin of the control flow
89258926
// analysis to include the immediately enclosing function.
@@ -8932,7 +8933,7 @@ namespace ts {
89328933
// the entire control flow graph from the variable's declaration (i.e. when the flow container and
89338934
// declaration container are the same).
89348935
const assumeInitialized = !strictNullChecks || (type.flags & TypeFlags.Any) !== 0 || isParameter ||
8935-
flowContainer !== declarationContainer || isInAmbientContext(declaration);
8936+
isOuterVariable || isInAmbientContext(declaration);
89368937
const flowType = getFlowTypeOfReference(node, type, assumeInitialized, flowContainer);
89378938
// A variable is considered uninitialized when it is possible to analyze the entire control flow graph
89388939
// from declaration to use, and when the variable's declared type doesn't include undefined but the

0 commit comments

Comments
 (0)