-
Notifications
You must be signed in to change notification settings - Fork 12.8k
JSDoc @typedef not working as expected #25386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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. Declaration of Declaration of Declaration of Declaration of I hope this breakdown of different cases help solve the issue ! |
Please try upgrading your workspace to use |
The |
I installed "typescript.tsdk": "/Users/samh/.nvm/versions/node/v8.10.0/lib/node_modules/typescript/lib" This still doesn't show the options: However, if I start to type an option, it does display. I think I shouldn't have to start typing in order to see what options are available. |
I see a similar behavior when using a typedef reference in /**
* @typedef {object} CancelReservationResult
* @property {number} updated 1 if the vehicle was updated, zero otherwise
* @property {boolean} [vehicle] - The updated vehicle
* @property {boolean} [reservation] - The former reservation of the updated vehicle
* @memberof VehicleService
*/
//some code in between
/**
* @summary Remove a reservation from a vehicle if that reservation is owned by the given user
*
* @param {Object} params
* @param {Number} vehicleId The vehicle that will have its reservation removed
* @param {Number} userId The user holding the reservation
* @returns {VehicleService.CancelReservationResult}
*/
// service method declaration... The returns section in intellisense is completely empty. I have tried referencing the type with different patterns. jsdoc picks it up correctly. |
@Lenophie I'm not familiar with that syntax, what is it? |
Should be working correctly in latest drop of TypeSript ( |
The following works for me, to get a typedef from another file: /** @typedef {object} EncodeVideox265Options
* @property {import('./ffprobe').VideoDimensions} dimensions Dimensions of the *original* video.
* @property {string} source Path to source file.
* @property {string} target Path to target file.
*/ // file: ffprobe.js
/** @typedef {object} VideoDimensions
* @property {number} height Height of the video in pixels.
* @property {number} width Width of the video in pixels.
*/ However, in a different situation, the following doesn't work despite all typedefs being in the same file: 'use strict';
/**
* Transcodes a file from the given message.
* @param {TranscodeMessage} message
*/
function handleMessage(message) {
message.payload.?????
}
module.exports = handleMessage;
/** @typedef {object} TranscodeMessage
* @property {TranscodePayload} payload
*/
/** @typedef {object} TranscodePayload
* @property {string} service Service name.
* @property {string} action Action name.
*/ Changing the 2nd examples typedef to use the /** @typedef {object} TranscodeMessage
* @property {import('./transcode').TranscodePayload} payload
*/
// ... |
After setting VSCode to use Here is what I did: 1.) > mkdir \usr && cd \usr
> npm install typescript@next 2.) Change vscode settings: {
"typescript.tsdk": "C:\\usr\\node_modules\\typescript\\lib",
} 3.) Restart VSCode |
None of the above works for me.
But if I get to that final argument and hit ctrl-space to trigger suggestions, I see the properties: I've tried stable TypeScript and |
@ffxsam The |
@Andy-MS I did change my syntax to use |
OK, could you write down the full updated example? For example, the following is working for me: a.js /**
* @typedef {object} T
* @property {number} x
*/
export {}; b.js /** @type {import("./a").T} */
const o = { x: 0 }; Did discover #25624 though. |
Confirmed, I started a fresh folder with three simple files and it works (even with the built-in version of TypeScript), though maybe not ideally. core.js /**
* @typedef {object} ApiOptions
* @property {boolean} debugMode
* @property {number} delay
*/
/**
* Does stuff.
* @param {ApiOptions} [options]
*/
export function magic(options) {} helpers.js import { magic } from './core';
/**
* Wrapper func.
* @param {import('./core').ApiOptions} [options]
*/
export function wrapper(options) {
magic(options);
} index.js import { wrapper } from './helpers';
wrapper({}); Now, in index.js, when I type If I hit the key shortcut for Trigger Suggest, though, then I see the individual options in the typedef: Stand by, going to try to replicate the instance where this is not working at all. |
Ah, never mind. I was missing the |
@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 Is this still 'working' for you? Is doing something special/particular needed? |
Hey @chrisaljoudi, I honestly couldn't tell you, as I've stopped using JSDoc and entirely use TypeScript annotations to document my stuff, and it works like a charm. |
I vaguely remember seeing this trick in a GitHub issue thread, but I can't recall where. A bit of searching gave me this: microsoft/TypeScript#25386 (comment) ...but I cannot verify that @Andy-MS came up with this trick.
I am using vscode 1.51 (the latest one as in 2020.12) but I still can't get typedef object's property show. So I stick with
|
From @ffxsam on June 29, 2018 16:44
@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
:And in
index.js
, I importapiCall
but the JSDoc hints don't show the properties ofApiOptions
:Also, typdefs should be able to be "exportable". I modified
funcs.js
to this:I added a new file called
middle.js
: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
The text was updated successfully, but these errors were encountered: