You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code能否结合TypeScript类型自动生成带类型的JSDoc?

How to Auto-Infer TypeScript Types in JSDoc Comments in VS Code

Absolutely, you can get VS Code to auto-populate JSDoc comments with TypeScript parameter types exactly like you want! Here are two reliable ways to set this up:

1. Enable VS Code's Native Type Inference

VS Code has a built-in setting that pulls TypeScript type info directly into generated JSDoc comments. Here's how to turn it on:

  • Open Settings: Press Ctrl+, (Windows/Linux) or Cmd+, (Mac)
  • Search for "typescript.preferences.jsDoc.inferTypes"
  • Toggle the setting to true

Once enabled, when you type /** above your function and press Enter, VS Code will automatically add the parameter type in curly braces:

/**
 * 
 * @param {string} param 
 */
const myFunction = (param: string) => {
  // ...
};

2. Use a Dedicated Extension for Enhanced Control

If you want more robust comment generation (like auto-adding return types, handling complex types such as interfaces or generics, and customizable templates), try the Document This extension:

  • Install it from the VS Code Marketplace
  • Trigger it by typing /** above your function and pressing Enter, or use the shortcut Ctrl+Alt+D twice
  • It will automatically inject TypeScript types into your JSDoc tags, along with structured comment scaffolding

This extension works seamlessly with both TypeScript and JavaScript projects, and you can tweak its output format via settings if needed.

内容的提问来源于stack exchange,提问作者r-gee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 07:57:34