From 1f9153f801718b34a30ff1bdca6513afcb85eca3 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 1 Mar 2016 12:26:17 -0800 Subject: [PATCH] Update to push types through as well --- src/compiler/checker.ts | 14 ++++++-- .../fourslash/getJavaScriptQuickInfo7.ts | 34 ++++++++----------- .../fourslash/getJavaScriptQuickInfo8.ts | 29 ++++++++++++++++ 3 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 tests/cases/fourslash/getJavaScriptQuickInfo8.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 692b6ea848b..eeece6d7c07 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.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/tests/cases/fourslash/getJavaScriptQuickInfo7.ts b/tests/cases/fourslash/getJavaScriptQuickInfo7.ts index 2c8e40131e5..5aa8474757d 100644 --- a/tests/cases/fourslash/getJavaScriptQuickInfo7.ts +++ b/tests/cases/fourslash/getJavaScriptQuickInfo7.ts @@ -2,25 +2,19 @@ // @allowNonTsExtensions: true // @Filename: file.js -//// let x = { -//// /** This is cool*/ -//// get m() { -//// return 0; -//// } +//// /** +//// * This is a very cool function that is very nice. +//// * @returns something +//// * @param p anotherthing +//// */ +//// function a1(p) { +//// try { +//// throw new Error('x'); +//// } catch (x) { x--; } +//// return 23; //// } -//// x.m/*1*/; -//// -//// class Foo { -//// /** This is cool too*/ -//// get b() { -//// return 0; -//// } -//// } -//// var y = new Foo(); -//// y.b/*2*/; +//// +//// x - /**/a1() -goTo.marker('1'); -verify.quickInfoIs(undefined, 'This is cool'); - -goTo.marker('2'); -verify.quickInfoIs(undefined, 'This is cool too'); +goTo.marker(); +verify.quickInfoExists(); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptQuickInfo8.ts b/tests/cases/fourslash/getJavaScriptQuickInfo8.ts new file mode 100644 index 00000000000..09ac27ce595 --- /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');