@@ -10242,8 +10242,11 @@ namespace ts {
1024210242 return reference.flowNode && (type.flags & TypeFlags.Narrowable || couldBeUninitialized);
1024310243 }
1024410244
10245- function getFlowTypeOfReference(reference: Node, declaredType: Type, initialType = declaredType, flowContainer?: Node) {
10245+ function getFlowTypeOfReference(reference: Node, declaredType: Type, initialType = declaredType, flowContainer?: Node, couldBeUninitialized?: boolean ) {
1024610246 let key: string;
10247+ if (!isFlowNarrowable(reference, declaredType, couldBeUninitialized)) {
10248+ return declaredType;
10249+ }
1024710250 const visitedFlowStart = visitedFlowCount;
1024810251 const evolvedType = getTypeFromFlowType(getTypeAtFlowNode(reference.flowNode));
1024910252 visitedFlowCount = visitedFlowStart;
@@ -11053,7 +11056,7 @@ namespace ts {
1105311056 const initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, getRootDeclaration(declaration) as VariableLikeDeclaration) : type) :
1105411057 type === autoType || type === autoArrayType ? undefinedType :
1105511058 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) ;
1105711060 // A variable is considered uninitialized when it is possible to analyze the entire control flow graph
1105811061 // from declaration to use, and when the variable's declared type doesn't include undefined but the
1105911062 // control flow based type does include undefined.
@@ -11319,7 +11322,7 @@ namespace ts {
1131911322 if (isClassLike(container.parent)) {
1132011323 const symbol = getSymbolOfNode(container.parent);
1132111324 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);
1132311326 }
1132411327
1132511328 if (isInJavaScriptFile(node)) {
@@ -13310,7 +13313,7 @@ namespace ts {
1331013313 !(prop.flags & SymbolFlags.Method && propType.flags & TypeFlags.Union)) {
1331113314 return propType;
1331213315 }
13313- const flowType = isFlowNarrowable(node, propType) ? getFlowTypeOfReference(node, propType) : propType ;
13316+ const flowType = getFlowTypeOfReference(node, propType);
1331413317 return assignmentKind ? getBaseTypeOfLiteralType(flowType) : flowType;
1331513318 }
1331613319
0 commit comments