@@ -4158,6 +4158,7 @@ namespace ts {
4158
4158
const types: Type[] = [];
4159
4159
let definedInConstructor = false;
4160
4160
let definedInMethod = false;
4161
+ let jsDocType: Type;
4161
4162
for (const declaration of symbol.declarations) {
4162
4163
const expression = declaration.kind === SyntaxKind.BinaryExpression ? <BinaryExpression>declaration :
4163
4164
declaration.kind === SyntaxKind.PropertyAccessExpression ? <BinaryExpression>getAncestor(declaration, SyntaxKind.BinaryExpression) :
@@ -4176,19 +4177,26 @@ namespace ts {
4176
4177
}
4177
4178
}
4178
4179
4179
- if (expression.flags & NodeFlags.JavaScriptFile) {
4180
- // If there is a JSDoc type, use it
4181
- const type = getTypeForDeclarationFromJSDocComment(expression.parent);
4182
- if (type && type !== unknownType) {
4183
- types.push(getWidenedType(type));
4184
- continue;
4180
+ // If there is a JSDoc type, use it
4181
+ const type = getTypeForDeclarationFromJSDocComment(expression.parent);
4182
+ if (type) {
4183
+ const declarationType = getWidenedType(type);
4184
+ if (!jsDocType) {
4185
+ jsDocType = declarationType;
4186
+ }
4187
+ else if (jsDocType !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(jsDocType, declarationType)) {
4188
+ const name = getNameOfDeclaration(declaration);
4189
+ error(name, Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, declarationNameToString(name), typeToString(jsDocType), typeToString(declarationType));
4185
4190
}
4186
4191
}
4187
-
4188
- types.push(getWidenedLiteralType(checkExpressionCached(expression.right)));
4192
+ else if (!jsDocType) {
4193
+ // If we don't have an explicit JSDoc type, get the type from the expression.
4194
+ types.push(getWidenedLiteralType(checkExpressionCached(expression.right)));
4195
+ }
4189
4196
}
4190
4197
4191
- return getWidenedType(addOptionality(getUnionType(types, /*subtypeReduction*/ true), definedInMethod && !definedInConstructor));
4198
+ const type = jsDocType || getUnionType(types, /*subtypeReduction*/ true);
4199
+ return getWidenedType(addOptionality(type, definedInMethod && !definedInConstructor));
4192
4200
}
4193
4201
4194
4202
// Return the type implied by a binding pattern element. This is the type of the initializer of the element if
@@ -13229,7 +13237,7 @@ namespace ts {
13229
13237
}
13230
13238
return result;
13231
13239
}
13232
- }
13240
+ }
13233
13241
13234
13242
function isValidSpreadType(type: Type): boolean {
13235
13243
return !!(type.flags & (TypeFlags.Any | TypeFlags.Null | TypeFlags.Undefined | TypeFlags.NonPrimitive) ||
0 commit comments