admin管理员组文章数量:1410674
Even tought Javascript is not a strong typed language I would like to tell VSCode about the type of some variables.
Like the snippet code in image below I would like to tell VSCode that task_id is a string variable.
I tried to specify it using a ment before the variable declaration (I've see this trick from this answer, but that apparently doesn't work with VSCode. Is there any VSCode plugin or something else to do that?
Even tought Javascript is not a strong typed language I would like to tell VSCode about the type of some variables.
Like the snippet code in image below I would like to tell VSCode that task_id is a string variable.
I tried to specify it using a ment before the variable declaration (I've see this trick from this answer, but that apparently doesn't work with VSCode. Is there any VSCode plugin or something else to do that?
Share Improve this question asked Feb 12, 2019 at 12:23 alexpfxalexpfx 6,71013 gold badges58 silver badges94 bronze badges 6-
1
Either define the callback somewhere else and document it (you can use the plugin "document this" for javascript in vscode), or use typescript instead. There isn't much else to do. Like this: prntscr./mk18xx . Plugin: marketplace.visualstudio./items?itemName=joelday.docthis ; use
ctrl + alt + D + D
to document. – briosheje Commented Feb 12, 2019 at 12:24 - 2 VSCode is perfectly able to recognize JSDoc (usejsdoc) – Seblor Commented Feb 12, 2019 at 12:31
- thanks, by moving the and documenting the callback it works fine. – alexpfx Commented Feb 12, 2019 at 12:42
- Please include code as text and not as image. – t.niese Commented Feb 12, 2019 at 13:30
- 1 @alexpfx you still should add the code as text, and provide the image as additional information. If someone want to use your code to create a plete answer, then the person can't use the copy functionality, but has to type everything. And not everyone is that lucky to have good eye sight, needs e.g. screen reader or has other color setting and I would guess auto pletion would be a helpful tool for them too. – t.niese Commented Feb 12, 2019 at 13:54
1 Answer
Reset to default 4Use the jsdoc documentation, I suggest you to install the document this plugin: https://marketplace.visualstudio./items?itemName=joelday.docthis, this will allow you to easily document your (javascript) code.
Just isolate the callback, define the params, then document them following the jsdoc standards.
Otherwise, use typescript instead, which will allow you to define types and so on. https://www.typescriptlang/
You will need a transpiler, though.
本文标签: visual studio codeHow to tell to VSCode the type of a function parameter (Javascript)Stack Overflow
版权声明:本文标题:visual studio code - How to tell to VSCode the type of a function parameter (Javascript) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744985111a2636045.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论