-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Intellisense for object properties defined in multi-line JSDoc comments #11597
Comments
A workaround is to write: /**
* @param {{strProp: string, numProp: number}} obj - An object parameter with string and number properties
*/ but that doesn't allow for documenting the specific subkeys. |
@Kovensky Yeah, that does work, but the individual property documentation is the main reason I prefer the multi-line documenting. |
Sorry, didn't mean to close/reopen this... |
Would a solution to this also support destructured parameters as well? |
I haven't really used that pattern, but I would think it would. That seems to be an extension of the same underlying issue of being unable to document properties of object parameters. |
How about creating a @typedef /** * @typedef {Object} GetUsersParams * @property {number} page_size - Number of results to show in a page, optional? * @property {number} page_number - Page number, optional? * @property {Object} match_params - match query, optional? */ /** * @description getUsers function can be used to fetch users * @param {GetUsersParams} params - Provide appropriate props * @param {function} cb */ function getUsers(params, cb) { // do something } I tried this, but it doesn't work * @param {...GetUsersParams} params |
That's actually what I've been doing as a workaround, but it doesn't allow for documenting optional/default values. You also don't get the text descriptions in intellisense. I wouldn't say that's necessary, but it'd be nice. |
Has there been any update on this? The |
can you elaborate on this? |
@mhegazy Here's a code snippet: /**
* @typedef {Object} Opts
* @property {string} x
* @property {string=} y
*
* @param {Opts} opts
*/
function foo(opts) {
console.log(opts);
}
foo({x: 'abc'}); That call to foo() will be flagged because it's missing EDIT: Doing |
I think that is another bug. thanks for reporting it. filed #15916 to track it. |
I have a similar problem with stateless functional components in react, they are written with object destructuring and the trick with I have tried with /**
* @typedef Props
* @property {string} one - first
* @property {number} two - second
*
* @param {Props} props
*/
// doesn't work
function Component({one, two}) {
// stuff...
}
// works
function Component(props) {
const {one, two} = props
// stuff...
} thanks for any advice 😄 |
@zanza00 you can you specify the type inline: function Component(/** @type {Props} */ { one, two }) {
// stuff ...
} |
I can confirm that indeed it works, thanks |
Fix is up at #17352 |
@sandersn It's still not possible to have a destructured parameter with Example: /**
* @typedef BarBaz
* @property {string} bar
* @property {string} baz
*/
/**
* @param {BarBaz} options Your configuration object
*/
function foo({bar, baz}) {
} Error
I can change my code to: function foo(/** @type {BarBaz} */{bar, baz}) {
} but then where should I put the parameter description text? Also see webpack/webpack#6988 |
@mohsen1 destructured parameters now look up jsdoc |
What do you mean by Are we heading towards something like /**
* @param {number} $0.id An id
*/
function foo({ id }) {} ? |
@Shahor no the syntax you would use is either /**
* @param {Object} arg
* @param {number} arg.id An id
*/
function foo({ id }) {} OR /**
* @param {{ id: number }} arg
*/
function foo({ id }) {} |
@steph643 VS code 1.23 is running Typescript 2.8, which doesn't have the fix. |
@Shagon94 it should be: /**
* @param {Object} options the args object
* @param {number} options.alpha first number
* @param {number} options.bravo second number
* @param {Function} callback the callback function
* @returns {number}
*/
function addNumbersFromObject({ alpha = 1, bravo = 2 } = {}, callback = null) {
if (!callback) return alpha + bravo;
return callback(alpha + bravo);
}
console.log(addNumbersFromObject({ alpha: 2 })); |
Currently it doesn't look like the TypeScript parser recognizes properties for an object parameter if they are defined with separate
@param
declarations. Would it be possible to add support for this?Thanks!
The text was updated successfully, but these errors were encountered: