@@ -3051,6 +3051,11 @@ namespace ts {
3051
3051
return undefined;
3052
3052
}
3053
3053
3054
+ function isAutoVariableInitializer(initializer: Expression) {
3055
+ let expr = initializer && skipParentheses(initializer);
3056
+ return !expr || expr.kind === SyntaxKind.NullKeyword || expr.kind === SyntaxKind.Identifier && getResolvedSymbol(<Identifier>expr) === undefinedSymbol;
3057
+ }
3058
+
3054
3059
function addOptionality(type: Type, optional: boolean): Type {
3055
3060
return strictNullChecks && optional ? includeFalsyTypes(type, TypeFlags.Undefined) : type;
3056
3061
}
@@ -3090,9 +3095,10 @@ namespace ts {
3090
3095
}
3091
3096
3092
3097
// Use control flow type inference for non-ambient, non-exported var or let variables with no initializer
3098
+ // or a 'null' or 'undefined' initializer.
3093
3099
if (declaration.kind === SyntaxKind.VariableDeclaration && !isBindingPattern(declaration.name) &&
3094
3100
!(getCombinedNodeFlags(declaration) & NodeFlags.Const) && !(getCombinedModifierFlags(declaration) & ModifierFlags.Export) &&
3095
- !declaration.initializer && !isInAmbientContext (declaration)) {
3101
+ !isInAmbientContext( declaration) && isAutoVariableInitializer (declaration.initializer )) {
3096
3102
return autoType;
3097
3103
}
3098
3104
@@ -8965,7 +8971,7 @@ namespace ts {
8965
8971
if (isRightSideOfQualifiedNameOrPropertyAccess(location)) {
8966
8972
location = location.parent;
8967
8973
}
8968
- if (isExpression (location) && !isAssignmentTarget(location)) {
8974
+ if (isPartOfExpression (location) && !isAssignmentTarget(location)) {
8969
8975
const type = checkExpression(<Expression>location);
8970
8976
if (getExportSymbolOfValueSymbolIfExported(getNodeLinks(location).resolvedSymbol) === symbol) {
8971
8977
return type;
@@ -9146,7 +9152,7 @@ namespace ts {
9146
9152
if (type === autoType) {
9147
9153
if (flowType === autoType) {
9148
9154
if (compilerOptions.noImplicitAny) {
9149
- error(declaration.name, Diagnostics.Variable_0_implicitly_has_type_any_and_is_referenced_in_a_nested_function , symbolToString(symbol));
9155
+ error(declaration.name, Diagnostics.Variable_0_implicitly_has_type_any_in_some_locations_where_its_type_cannot_be_determined , symbolToString(symbol));
9150
9156
}
9151
9157
return anyType;
9152
9158
}
0 commit comments