diff --git a/src/services/completions.ts b/src/services/completions.ts index c8a0e50372f..f3a8e5f65a7 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -3005,8 +3005,7 @@ function getCompletionData( // Since this is qualified name check it's a type node location const isImportType = isLiteralImportTypeNode(node); - const isTypeLocation = insideJsDocTagTypeExpression - || (isImportType && !(node as ImportTypeNode).isTypeOf) + const isTypeLocation = (isImportType && !(node as ImportTypeNode).isTypeOf) || isPartOfTypeNode(node.parent) || isPossiblyTypeArgumentPosition(contextToken, sourceFile, typeChecker); const isRhsOfImportDeclaration = isInRightSideOfInternalImportEqualsDeclaration(node); @@ -3029,7 +3028,7 @@ function getCompletionData( : isRhsOfImportDeclaration ? // Any kind is allowed when dotting off namespace in internal import equals declaration symbol => isValidTypeAccess(symbol) || isValidValueAccess(symbol) : - isTypeLocation ? isValidTypeAccess : isValidValueAccess; + isTypeLocation || insideJsDocTagTypeExpression ? isValidTypeAccess : isValidValueAccess; for (const exportedSymbol of exportedSymbols) { if (isValidAccess(exportedSymbol)) { symbols.push(exportedSymbol); @@ -3038,6 +3037,7 @@ function getCompletionData( // If the module is merged with a value, we must get the type of the class and add its propertes (for inherited static methods). if (!isTypeLocation && + !insideJsDocTagTypeExpression && symbol.declarations && symbol.declarations.some(d => d.kind !== SyntaxKind.SourceFile && d.kind !== SyntaxKind.ModuleDeclaration && d.kind !== SyntaxKind.EnumDeclaration)) { let type = typeChecker.getTypeOfSymbolAtLocation(symbol, node).getNonOptionalType(); diff --git a/tests/baselines/reference/jsFileJsdocTypedefTagTypeExpressionCompletion4.baseline b/tests/baselines/reference/jsFileJsdocTypedefTagTypeExpressionCompletion4.baseline new file mode 100644 index 00000000000..31b55c76e24 --- /dev/null +++ b/tests/baselines/reference/jsFileJsdocTypedefTagTypeExpressionCompletion4.baseline @@ -0,0 +1,132 @@ +=== /a.js === +// const foo = { +// bar: { +// baz: 42, +// } +// } +// /** @typedef { typeof foo. } Foo */ +// ^ +// | ---------------------------------------------------------------------- +// | (property) bar: { +// | baz: number; +// | } +// | (warning) baz +// | (warning) foo +// | (warning) Foo +// | ---------------------------------------------------------------------- + +[ + { + "marker": { + "fileName": "/a.js", + "position": 76, + "name": "" + }, + "item": { + "flags": 0, + "isGlobalCompletion": false, + "isMemberCompletion": true, + "isNewIdentifierLocation": false, + "entries": [ + { + "name": "bar", + "kind": "property", + "kindModifiers": "", + "sortText": "11", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "{", + "kind": "punctuation" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "baz", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, + { + "text": ";", + "kind": "punctuation" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "}", + "kind": "punctuation" + } + ], + "documentation": [] + }, + { + "name": "baz", + "kind": "warning", + "kindModifiers": "", + "sortText": "18", + "isFromUncheckedFile": true + }, + { + "name": "foo", + "kind": "warning", + "kindModifiers": "", + "sortText": "18", + "isFromUncheckedFile": true + }, + { + "name": "Foo", + "kind": "warning", + "kindModifiers": "", + "sortText": "18", + "isFromUncheckedFile": true + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion4.ts b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion4.ts new file mode 100644 index 00000000000..e7c9f209fc9 --- /dev/null +++ b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion4.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @filename: /a.js +////const foo = { +//// bar: { +//// baz: 42, +//// } +////} +/////** @typedef { typeof foo./**/ } Foo */ + +verify.baselineCompletions();