TypeScript: JSDoc @typedef not working as expected
From @ffxsam on June 29, 2018 16:44
- VSCode Version: 1.24.1
- OS Version: macOS 10.13.5
@typedef support seems a bit buggy. There are a couple of things going on, but related.
First, typdefs with properties don’t seem to work as expected. I have the following file, funcs.js:
/**
* API options.
* @typedef {Object} ApiOptions
* @property {number} artificialDelay Number of milliseconds for an artificial delay
* @property {boolean} debug Debug mode
*/
/**
*
* @param {string} url URL to call
* @param {ApiOptions} [options] API options
*/
export function apiCall(url, options = {}) {}
And in index.js, I import apiCall but the JSDoc hints don’t show the properties of ApiOptions:
Also, typdefs should be able to be “exportable”. I modified funcs.js to this:
/** @module api */
/**
* API options.
* @typedef {Object} module:api.ApiOptions
* @property {number} artificialDelay Number of milliseconds for an artificial delay
* @property {boolean} debug Debug mode
*/
/**
*
* @param {string} url URL to call
* @param {module:api.ApiOptions} [options] API options
*/
export function apiCall(url, options = {}) {}
I added a new file called middle.js:
import { apiCall } from './funcs';
/**
*
* @param {module:api.ApiOptions} options
*/
export function test(options) {}
VSCode doesn’t seem to understand this usage at all:
It would be great if VSCode fully supported this for projects that aren’t using TypeScript.
Does this issue occur when all extensions are disabled?: Yes
Copied from original issue: Microsoft/vscode#53348
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 21 (4 by maintainers)
From @Lenophie on June 30, 2018 22:10
What’s weird is Intellisense/VSCode already exports typedef across a project by default BUT it can fail if the custom type uses other custom types. Here are some test cases.
Declaration of
Declaration of a variable of type
Quick info works. 👍
Displayed type is correct. 👍
Displayed type property is correct. 👍
CustomTypein a file :CustomTypein another file :Declaration of
Declaration of a variable of type
Quick info doesn’t work. 👎
CustomTypeusing another custom typeCustomType2in a file :CustomTypein another file :Declaration of
Quick info works. 👍
Displayed type is correct. 👍
Displayed type property is correct. 👍
CustomTypeusing another custom typeCustomType2AND declaration of a variable of typeCustomTypein the same file :Declaration of
Quick info works. 👍
Displayed type is correct. 👍
Displayed type property is wrong. 👎
CustomTypeAND declaration of a variable of typeCustomTypein the same file BUT declaration ofCustomType2in another file :I hope this breakdown of different cases help solve the issue !
The following works for me, to get a typedef from another file:
However, in a different situation, the following doesn’t work despite all typedefs being in the same file:
Changing the 2nd examples typedef to use the
import('./same-file').TranscodePayloaddoes work:Ah, never mind. I was missing the
importin my referenes toApiOptions. Also, it works fine in JS files, but not Vue files, so this is now a Vetur issue.here is what i see on
typescript@next:@ffxsam hey—sorry to hijack, and this has obviously been a while. I’ve been trying to get the exact behavior you’re talking about: the individual options/properties defined inside a
typedefto expand automatically inside what VS Code shows in its tooltip. I simply cannot get that behavior to occur. It always seems to require doing the Trigger Suggest keyboard shortcut.Is this still ‘working’ for you? Is doing something special/particular needed?
@ffxsam The
{module:api.ApiOptions}syntax isn’t supported. Try just@typedef {Object} ApiOptionsand reference it with{ApiOptions}(in the same module) or{import("./funcs").ApiOptions}(from a different module).