diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 692b6ea848bf0..97eb15cd0d9fe 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2958,12 +2958,22 @@ namespace ts { function getTypeOfAccessors(symbol: Symbol): Type { const links = getSymbolLinks(symbol); if (!links.type) { + const getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor); + const setter = getDeclarationOfKind(symbol, SyntaxKind.SetAccessor); + + if (getter && getter.flags & NodeFlags.JavaScriptFile) { + const jsDocType = getTypeForVariableLikeDeclarationFromJSDocComment(getter); + if (jsDocType) { + return links.type = jsDocType; + } + } + if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) { return unknownType; } - const getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor); - const setter = getDeclarationOfKind(symbol, SyntaxKind.SetAccessor); + let type: Type; + // First try to see if the user specified a return type on the get-accessor. const getterReturnType = getAnnotatedAccessorType(getter); if (getterReturnType) { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index db9639156a58e..e7e45a19a93be 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3954,7 +3954,7 @@ namespace ts { function tryParseAccessorDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): AccessorDeclaration { if (parseContextualModifier(SyntaxKind.GetKeyword)) { - return parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, decorators, modifiers); + return addJSDocComment(parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, decorators, modifiers)); } else if (parseContextualModifier(SyntaxKind.SetKeyword)) { return parseAccessorDeclaration(SyntaxKind.SetAccessor, fullStart, decorators, modifiers); diff --git a/tests/cases/fourslash/getJavaScriptQuickInfo8.ts b/tests/cases/fourslash/getJavaScriptQuickInfo8.ts new file mode 100644 index 0000000000000..09ac27ce5955e --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptQuickInfo8.ts @@ -0,0 +1,29 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: file.js +//// let x = { +//// /** @type {number} */ +//// get m() { +//// return undefined; +//// } +//// } +//// x.m/*1*/; +//// +//// class Foo { +//// /** @type {string} */ +//// get b() { +//// return undefined; +//// } +//// } +//// var y = new Foo(); +//// y.b/*2*/; + +goTo.marker('1'); +edit.insert('.'); +verify.memberListContains('toFixed', undefined, undefined, 'method'); +edit.backspace(); + +goTo.marker('2'); +edit.insert('.'); +verify.memberListContains('substr', undefined, undefined, 'method');