@@ -10242,8 +10242,11 @@ namespace ts {
10242
10242
return reference.flowNode && (type.flags & TypeFlags.Narrowable || couldBeUninitialized);
10243
10243
}
10244
10244
10245
- function getFlowTypeOfReference(reference: Node, declaredType: Type, initialType = declaredType, flowContainer?: Node) {
10245
+ function getFlowTypeOfReference(reference: Node, declaredType: Type, initialType = declaredType, flowContainer?: Node, couldBeUninitialized?: boolean ) {
10246
10246
let key: string;
10247
+ if (!isFlowNarrowable(reference, declaredType, couldBeUninitialized)) {
10248
+ return declaredType;
10249
+ }
10247
10250
const visitedFlowStart = visitedFlowCount;
10248
10251
const evolvedType = getTypeFromFlowType(getTypeAtFlowNode(reference.flowNode));
10249
10252
visitedFlowCount = visitedFlowStart;
@@ -11053,7 +11056,7 @@ namespace ts {
11053
11056
const initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, getRootDeclaration(declaration) as VariableLikeDeclaration) : type) :
11054
11057
type === autoType || type === autoArrayType ? undefinedType :
11055
11058
includeFalsyTypes(type, TypeFlags.Undefined);
11056
- const flowType = isFlowNarrowable(node, type, !assumeInitialized) ? getFlowTypeOfReference(node, type, initialType, flowContainer) : type ;
11059
+ const flowType = getFlowTypeOfReference(node, type, initialType, flowContainer, !assumeInitialized) ;
11057
11060
// A variable is considered uninitialized when it is possible to analyze the entire control flow graph
11058
11061
// from declaration to use, and when the variable's declared type doesn't include undefined but the
11059
11062
// control flow based type does include undefined.
@@ -11319,7 +11322,7 @@ namespace ts {
11319
11322
if (isClassLike(container.parent)) {
11320
11323
const symbol = getSymbolOfNode(container.parent);
11321
11324
const type = hasModifier(container, ModifierFlags.Static) ? getTypeOfSymbol(symbol) : (<InterfaceType>getDeclaredTypeOfSymbol(symbol)).thisType;
11322
- return isFlowNarrowable(node, type) ? getFlowTypeOfReference(node, type) : type ;
11325
+ return getFlowTypeOfReference(node, type);
11323
11326
}
11324
11327
11325
11328
if (isInJavaScriptFile(node)) {
@@ -13310,7 +13313,7 @@ namespace ts {
13310
13313
!(prop.flags & SymbolFlags.Method && propType.flags & TypeFlags.Union)) {
13311
13314
return propType;
13312
13315
}
13313
- const flowType = isFlowNarrowable(node, propType) ? getFlowTypeOfReference(node, propType) : propType ;
13316
+ const flowType = getFlowTypeOfReference(node, propType);
13314
13317
return assignmentKind ? getBaseTypeOfLiteralType(flowType) : flowType;
13315
13318
}
13316
13319
0 commit comments