@@ -27275,6 +27275,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2727527275 const isOuterVariable = flowContainer !== declarationContainer;
2727627276 const isSpreadDestructuringAssignmentTarget = node.parent && node.parent.parent && isSpreadAssignment(node.parent) && isDestructuringAssignmentTarget(node.parent.parent);
2727727277 const isModuleExports = symbol.flags & SymbolFlags.ModuleExports;
27278+ const typeIsAutomatic = type === autoType || type === autoArrayType;
27279+ const isAutomaticTypeInNonNull = typeIsAutomatic && node.parent.kind === SyntaxKind.NonNullExpression;
2727827280 // When the control flow originates in a function expression or arrow function and we are referencing
2727927281 // a const variable or parameter from an outer function, we extend the origin of the control flow
2728027282 // analysis to include the immediately enclosing function.
@@ -27292,10 +27294,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2729227294 node.parent.kind === SyntaxKind.NonNullExpression ||
2729327295 declaration.kind === SyntaxKind.VariableDeclaration && (declaration as VariableDeclaration).exclamationToken ||
2729427296 declaration.flags & NodeFlags.Ambient;
27295- const initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, declaration as VariableLikeDeclaration) : type) :
27296- type === autoType || type === autoArrayType ? undefinedType :
27297- getOptionalType(type);
27298- const flowType = getFlowTypeOfReference(node, type, initialType, flowContainer);
27297+ const initialType = isAutomaticTypeInNonNull ? undefinedType :
27298+ assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, declaration as VariableLikeDeclaration) : type) :
27299+ typeIsAutomatic ? undefinedType : getOptionalType(type);
27300+ const flowType = isAutomaticTypeInNonNull ? getNonNullableType(getFlowTypeOfReference(node, type, initialType, flowContainer)) :
27301+ getFlowTypeOfReference(node, type, initialType, flowContainer);
2729927302 // A variable is considered uninitialized when it is possible to analyze the entire control flow graph
2730027303 // from declaration to use, and when the variable's declared type doesn't include undefined but the
2730127304 // control flow based type does include undefined.
0 commit comments