简体   繁体   中英

JSDoc typedef methods in VS Code

I have an issue when trying to document javascript methods,

I tried this: 在此处输入图像描述

I really don't think I should be setting a property for getMother() but rather a method.

Yet I don't know if it's even supported (I'm using VS Code).

So the given example might work, but it doesn't add parenthesis when autocompleting and just isn't clean because we are seeing it as a property.

I spent a few hours searching for a solution and failed. I hope someone knows the answer, feel free to ask for more details.

You can try something like this:

// @ts-check

/*
 * @typedef {{
 * age: number,
 * getMother(arg1: string, arg2: string): HTMLCat
 * } & HTMLElement} HTMLCat
 */

/*
 * @type {HTMLCat}
 */
var cat;

cat.getMother('a', 'b').age

I'm not sure what AdditionalCat is doing exactly since it's just an object, which would likely correlate with the key/value index I added, so I left it out. But this syntax might be a bit easier to reason about.

You can find more examples here: https://medium.com/better-programming/type-checking-in-vscode-without-typescript-eba92161cd08

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM