Skip to content

Commit 98ab0de

Browse files
ahejlsbergmhegazy
authored andcommitted
Assume outer variables are always initialized in control flow analysis
1 parent 11e9f50 commit 98ab0de

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
@@ -8881,6 +8881,7 @@ namespace ts {
88818881
const isParameter = getRootDeclaration(declaration).kind === SyntaxKind.Parameter;
88828882
const declarationContainer = getControlFlowContainer(declaration);
88838883
let flowContainer = getControlFlowContainer(node);
8884+
const isOuterVariable = flowContainer !== declarationContainer;
88848885
// When the control flow originates in a function expression or arrow function and we are referencing
88858886
// a const variable or parameter from an outer function, we extend the origin of the control flow
88868887
// analysis to include the immediately enclosing function.
@@ -8893,7 +8894,7 @@ namespace ts {
88938894
// the entire control flow graph from the variable's declaration (i.e. when the flow container and
88948895
// declaration container are the same).
88958896
const assumeInitialized = !strictNullChecks || (type.flags & TypeFlags.Any) !== 0 || isParameter ||
8896-
flowContainer !== declarationContainer || isInAmbientContext(declaration);
8897+
isOuterVariable || isInAmbientContext(declaration);
88978898
const flowType = getFlowTypeOfReference(node, type, assumeInitialized, flowContainer);
88988899
// A variable is considered uninitialized when it is possible to analyze the entire control flow graph
88998900
// from declaration to use, and when the variable's declared type doesn't include undefined but the

0 commit comments

Comments
 (0)