Skip to content

Commit 0e3ac3f

Browse files
committed
fix getting type from initializer
1 parent 2d81c57 commit 0e3ac3f

7 files changed

+8452
-6
lines changed

src/compiler/checker.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -45461,9 +45461,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4546145461
return symbol ? getDeclaredTypeOfSymbol(symbol) : errorType;
4546245462
}
4546345463

45464+
if (isBindingElement(node)) {
45465+
return getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ true, CheckMode.Normal) || errorType;
45466+
}
45467+
4546445468
if (isDeclaration(node)) {
4546545469
// In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
45466-
const symbol = getSymbolOfDeclaration(node);
45470+
const symbol = getSymbolOfDeclaration(node) || getSymbolAtLocation(node);
4546745471
return symbol ? getTypeOfSymbol(symbol) : errorType;
4546845472
}
4546945473

src/services/completions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ function getJSDocParamAnnotation(
10991099
else {
11001100
if (initializer) {
11011101
const inferredType = checker.getTypeAtLocation(initializer.parent);
1102-
if (!(inferredType.flags & TypeFlags.Any)) {
1102+
if (!(inferredType.flags & (TypeFlags.Any | TypeFlags.Void))) {
11031103
const sourceFile = initializer.getSourceFile();
11041104
const quotePreference = getQuotePreference(sourceFile, preferences);
11051105
const builderFlags = (quotePreference === QuotePreference.Single ? NodeBuilderFlags.UseSingleQuotesForStringLiteralType : NodeBuilderFlags.None);
@@ -1121,7 +1121,7 @@ function getJSDocParamAnnotation(
11211121
}
11221122
}
11231123
}
1124-
if (isSnippet) {
1124+
if (isSnippet && type === "*") {
11251125
type = `\${${tabstopCounter!.tabstop++}:${type}}`;
11261126
}
11271127
}

tests/baselines/reference/jsdocParameterTagSnippetCompletion1.baseline

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
// | virtual
8888
// | yields
8989
// | param {Object} param0
90-
// | * @param {*} [param0.a=1]
90+
// | * @param {number} [param0.a=1]
9191
// | param {*} b
9292
// | ----------------------------------------------------------------------
9393
// */
@@ -8263,13 +8263,13 @@
82638263
"documentation": []
82648264
},
82658265
{
8266-
"name": "param {Object} param0 \r\n* @param {*} [param0.a=1] ",
8266+
"name": "param {Object} param0 \r\n* @param {number} [param0.a=1] ",
82678267
"kind": "",
82688268
"sortText": "11",
82698269
"kindModifiers": "",
82708270
"displayParts": [
82718271
{
8272-
"text": "param {Object} param0 \r\n* @param {*} [param0.a=1] ",
8272+
"text": "param {Object} param0 \r\n* @param {number} [param0.a=1] ",
82738273
"kind": "text"
82748274
}
82758275
],

0 commit comments

Comments
 (0)