@@ -7737,7 +7737,7 @@ namespace ts {
7737
7737
}
7738
7738
7739
7739
// Return the inferred type for a variable, parameter, or property declaration
7740
- function getTypeForVariableLikeDeclaration(declaration: ParameterDeclaration | PropertyDeclaration | PropertySignature | VariableDeclaration | BindingElement, includeOptionality: boolean): Type | undefined {
7740
+ function getTypeForVariableLikeDeclaration(declaration: ParameterDeclaration | PropertyDeclaration | PropertySignature | VariableDeclaration | BindingElement | JSDocPropertyLikeTag , includeOptionality: boolean): Type | undefined {
7741
7741
// A variable declared in a for..in statement is of type string, or of type keyof T when the
7742
7742
// right hand expression is of a type parameter type.
7743
7743
if (isVariableDeclaration(declaration) && declaration.parent.parent.kind === SyntaxKind.ForInStatement) {
@@ -7760,6 +7760,7 @@ namespace ts {
7760
7760
7761
7761
const isOptional = includeOptionality && (
7762
7762
isParameter(declaration) && isJSDocOptionalParameter(declaration)
7763
+ || isOptionalJSDocPropertyLikeTag(declaration)
7763
7764
|| !isBindingElement(declaration) && !isVariableDeclaration(declaration) && !!declaration.questionToken);
7764
7765
7765
7766
// Use type from type annotation if one is present
@@ -7769,7 +7770,7 @@ namespace ts {
7769
7770
}
7770
7771
7771
7772
if ((noImplicitAny || isInJSFile(declaration)) &&
7772
- declaration.kind === SyntaxKind.VariableDeclaration && !isBindingPattern(declaration.name) &&
7773
+ isVariableDeclaration( declaration) && !isBindingPattern(declaration.name) &&
7773
7774
!(getCombinedModifierFlags(declaration) & ModifierFlags.Export) && !(declaration.flags & NodeFlags.Ambient)) {
7774
7775
// If --noImplicitAny is on or the declaration is in a Javascript file,
7775
7776
// use control flow tracked 'any' type for non-ambient, non-exported var or let variables with no
@@ -7784,7 +7785,7 @@ namespace ts {
7784
7785
}
7785
7786
}
7786
7787
7787
- if (declaration.kind === SyntaxKind.Parameter ) {
7788
+ if (isParameter( declaration) ) {
7788
7789
const func = <FunctionLikeDeclaration>declaration.parent;
7789
7790
// For a parameter of a set accessor, use the type of the get accessor if one is present
7790
7791
if (func.kind === SyntaxKind.SetAccessor && !hasNonBindableDynamicName(func)) {
@@ -7814,16 +7815,16 @@ namespace ts {
7814
7815
return addOptionality(type, isOptional);
7815
7816
}
7816
7817
}
7817
- else if (isInJSFile(declaration)) {
7818
- const containerObjectType = getJSContainerObjectType(declaration, getSymbolOfNode(declaration), getDeclaredExpandoInitializer(declaration));
7819
- if (containerObjectType) {
7820
- return containerObjectType;
7821
- }
7822
- }
7823
7818
7824
7819
// Use the type of the initializer expression if one is present and the declaration is
7825
7820
// not a parameter of a contextually typed function
7826
- if (declaration.initializer) {
7821
+ if (hasOnlyExpressionInitializer(declaration) && !!declaration.initializer) {
7822
+ if (isInJSFile(declaration) && !isParameter(declaration)) {
7823
+ const containerObjectType = getJSContainerObjectType(declaration, getSymbolOfNode(declaration), getDeclaredExpandoInitializer(declaration));
7824
+ if (containerObjectType) {
7825
+ return containerObjectType;
7826
+ }
7827
+ }
7827
7828
const type = widenTypeInferredFromInitializer(declaration, checkDeclarationInitializer(declaration));
7828
7829
return addOptionality(type, isOptional);
7829
7830
}
@@ -8243,7 +8244,7 @@ namespace ts {
8243
8244
// Here, the array literal [1, "one"] is contextually typed by the type [any, string], which is the implied type of the
8244
8245
// binding pattern [x, s = ""]. Because the contextual type is a tuple type, the resulting type of [1, "one"] is the
8245
8246
// tuple type [number, string]. Thus, the type inferred for 'x' is number and the type inferred for 's' is string.
8246
- function getWidenedTypeForVariableLikeDeclaration(declaration: ParameterDeclaration | PropertyDeclaration | PropertySignature | VariableDeclaration | BindingElement, reportErrors?: boolean): Type {
8247
+ function getWidenedTypeForVariableLikeDeclaration(declaration: ParameterDeclaration | PropertyDeclaration | PropertySignature | VariableDeclaration | BindingElement | JSDocPropertyLikeTag , reportErrors?: boolean): Type {
8247
8248
return widenTypeForVariableLikeDeclaration(getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true), declaration, reportErrors);
8248
8249
}
8249
8250
@@ -8350,8 +8351,7 @@ namespace ts {
8350
8351
(isCallExpression(declaration) || (isPropertyAccessExpression(declaration) || isBindableStaticElementAccessExpression(declaration)) && isBinaryExpression(declaration.parent)))) {
8351
8352
type = getWidenedTypeForAssignmentDeclaration(symbol);
8352
8353
}
8353
- else if (isJSDocPropertyLikeTag(declaration)
8354
- || isPropertyAccessExpression(declaration)
8354
+ else if (isPropertyAccessExpression(declaration)
8355
8355
|| isElementAccessExpression(declaration)
8356
8356
|| isIdentifier(declaration)
8357
8357
|| isStringLiteralLike(declaration)
@@ -8385,7 +8385,8 @@ namespace ts {
8385
8385
|| isPropertyDeclaration(declaration)
8386
8386
|| isPropertySignature(declaration)
8387
8387
|| isVariableDeclaration(declaration)
8388
- || isBindingElement(declaration)) {
8388
+ || isBindingElement(declaration)
8389
+ || isJSDocPropertyLikeTag(declaration)) {
8389
8390
type = getWidenedTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true);
8390
8391
}
8391
8392
// getTypeOfSymbol dispatches some JS merges incorrectly because their symbol flags are not mutually exclusive.
@@ -11171,8 +11172,8 @@ namespace ts {
11171
11172
return symbol && withAugmentations ? getMergedSymbol(symbol) : symbol;
11172
11173
}
11173
11174
11174
- function isOptionalParameter(node: ParameterDeclaration | JSDocParameterTag) {
11175
- if (hasQuestionToken(node) || isOptionalJSDocParameterTag (node) || isJSDocOptionalParameter(node)) {
11175
+ function isOptionalParameter(node: ParameterDeclaration | JSDocParameterTag | JSDocPropertyTag ) {
11176
+ if (hasQuestionToken(node) || isOptionalJSDocPropertyLikeTag (node) || isJSDocOptionalParameter(node)) {
11176
11177
return true;
11177
11178
}
11178
11179
@@ -11192,8 +11193,8 @@ namespace ts {
11192
11193
return false;
11193
11194
}
11194
11195
11195
- function isOptionalJSDocParameterTag (node: Node): node is JSDocParameterTag {
11196
- if (!isJSDocParameterTag (node)) {
11196
+ function isOptionalJSDocPropertyLikeTag (node: Node): node is JSDocPropertyLikeTag {
11197
+ if (!isJSDocPropertyLikeTag (node)) {
11197
11198
return false;
11198
11199
}
11199
11200
const { isBracketed, typeExpression } = node;
@@ -11301,7 +11302,7 @@ namespace ts {
11301
11302
}
11302
11303
11303
11304
// Record a new minimum argument count if this is not an optional parameter
11304
- const isOptionalParameter = isOptionalJSDocParameterTag (param) ||
11305
+ const isOptionalParameter = isOptionalJSDocPropertyLikeTag (param) ||
11305
11306
param.initializer || param.questionToken || param.dotDotDotToken ||
11306
11307
iife && parameters.length > iife.arguments.length && !type ||
11307
11308
isJSDocOptionalParameter(param);
0 commit comments