Skip to content

Commit

Permalink
fix getting type from initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
gabritto committed Apr 3, 2023
1 parent 2d81c57 commit 0e3ac3f
Show file tree
Hide file tree
Showing 7 changed files with 8,452 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45461,9 +45461,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return symbol ? getDeclaredTypeOfSymbol(symbol) : errorType;
}

if (isBindingElement(node)) {
return getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ true, CheckMode.Normal) || errorType;
}

if (isDeclaration(node)) {
// In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
const symbol = getSymbolOfDeclaration(node);
const symbol = getSymbolOfDeclaration(node) || getSymbolAtLocation(node);
return symbol ? getTypeOfSymbol(symbol) : errorType;
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ function getJSDocParamAnnotation(
else {
if (initializer) {
const inferredType = checker.getTypeAtLocation(initializer.parent);
if (!(inferredType.flags & TypeFlags.Any)) {
if (!(inferredType.flags & (TypeFlags.Any | TypeFlags.Void))) {
const sourceFile = initializer.getSourceFile();
const quotePreference = getQuotePreference(sourceFile, preferences);
const builderFlags = (quotePreference === QuotePreference.Single ? NodeBuilderFlags.UseSingleQuotesForStringLiteralType : NodeBuilderFlags.None);
Expand All @@ -1121,7 +1121,7 @@ function getJSDocParamAnnotation(
}
}
}
if (isSnippet) {
if (isSnippet && type === "*") {
type = `\${${tabstopCounter!.tabstop++}:${type}}`;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
// | virtual
// | yields
// | param {Object} param0
// | * @param {*} [param0.a=1]
// | * @param {number} [param0.a=1]
// | param {*} b
// | ----------------------------------------------------------------------
// */
Expand Down Expand Up @@ -8263,13 +8263,13 @@
"documentation": []
},
{
"name": "param {Object} param0 \r\n* @param {*} [param0.a=1] ",
"name": "param {Object} param0 \r\n* @param {number} [param0.a=1] ",
"kind": "",
"sortText": "11",
"kindModifiers": "",
"displayParts": [
{
"text": "param {Object} param0 \r\n* @param {*} [param0.a=1] ",
"text": "param {Object} param0 \r\n* @param {number} [param0.a=1] ",
"kind": "text"
}
],
Expand Down
Loading

0 comments on commit 0e3ac3f

Please sign in to comment.