@@ -27275,6 +27275,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
27275
27275
const isOuterVariable = flowContainer !== declarationContainer;
27276
27276
const isSpreadDestructuringAssignmentTarget = node.parent && node.parent.parent && isSpreadAssignment(node.parent) && isDestructuringAssignmentTarget(node.parent.parent);
27277
27277
const isModuleExports = symbol.flags & SymbolFlags.ModuleExports;
27278
+ const typeIsAutomatic = type === autoType || type === autoArrayType;
27279
+ const isAutomaticTypeInNonNull = typeIsAutomatic && node.parent.kind === SyntaxKind.NonNullExpression;
27278
27280
// When the control flow originates in a function expression or arrow function and we are referencing
27279
27281
// a const variable or parameter from an outer function, we extend the origin of the control flow
27280
27282
// analysis to include the immediately enclosing function.
@@ -27292,10 +27294,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
27292
27294
node.parent.kind === SyntaxKind.NonNullExpression ||
27293
27295
declaration.kind === SyntaxKind.VariableDeclaration && (declaration as VariableDeclaration).exclamationToken ||
27294
27296
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);
27299
27302
// A variable is considered uninitialized when it is possible to analyze the entire control flow graph
27300
27303
// from declaration to use, and when the variable's declared type doesn't include undefined but the
27301
27304
// control flow based type does include undefined.
0 commit comments