Skip to content

Commit dda8aac

Browse files
committed
Unify anyType and autoType when checking for identical declarations
1 parent 864ee1c commit dda8aac

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15806,6 +15806,10 @@ namespace ts {
1580615806
}
1580715807
}
1580815808

15809+
function convertAutoToAny(type: Type) {
15810+
return type === autoType ? anyType : type;
15811+
}
15812+
1580915813
// Check variable, parameter, or property declaration
1581015814
function checkVariableLikeDeclaration(node: VariableLikeDeclaration) {
1581115815
checkDecorators(node);
@@ -15856,7 +15860,7 @@ namespace ts {
1585615860
return;
1585715861
}
1585815862
const symbol = getSymbolOfNode(node);
15859-
const type = getTypeOfVariableOrParameterOrProperty(symbol);
15863+
const type = convertAutoToAny(getTypeOfVariableOrParameterOrProperty(symbol));
1586015864
if (node === symbol.valueDeclaration) {
1586115865
// Node is the primary declaration of the symbol, just validate the initializer
1586215866
// Don't validate for-in initializer as it is already an error
@@ -15868,7 +15872,7 @@ namespace ts {
1586815872
else {
1586915873
// Node is a secondary declaration, check that type is identical to primary declaration and check that
1587015874
// initializer is consistent with type associated with the node
15871-
const declarationType = getWidenedTypeForVariableLikeDeclaration(node);
15875+
const declarationType = convertAutoToAny(getWidenedTypeForVariableLikeDeclaration(node));
1587215876
if (type !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(type, declarationType)) {
1587315877
error(node.name, Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, declarationNameToString(node.name), typeToString(type), typeToString(declarationType));
1587415878
}

0 commit comments

Comments
 (0)