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

如何防止JSDoc生成文档时@param类型变为无效死链接

问题

使用JSDoc生成项目文档时,string等基础类型会被自动转换为指向不存在的string.html页面的链接,需要阻止这类自动链接生成逻辑,让这些类型直接以纯文本形式展示。

问题对应的注释示例:

/**
 * the comment
 *
 * @param {string} myString
 */

当前使用的JSDoc配置如下:

{
  "opts": {
      "encoding": "utf8",
      "recurse": true,
      "destination": "out/clean/",
      "template": "./node_modules/clean-jsdoc-theme/"
  },
  "tags": {
      "allowUnknownTags": false,
      "dictionaries": ["jsdoc","closure"]
  },
  "source": {
      "includePattern": ".+\\.js?$",
      "include": ["path/to/file"]
  },
  "plugins": ["plugins/markdown"],
  "markdown": {
      "hardwrap": false,
      "idInHeadings": true
  }
}
解决方法
  • 全局配置内置基础类型不生成链接
    在JSDoc配置文件中新增types配置项,将所有JS内置基础类型加入builtInTypes列表,JSDoc会直接将列表内的类型渲染为纯文本,不会生成跳转链接:
{
  // 原有配置保留
  "types": {
    "builtInTypes": ["string", "number", "boolean", "null", "undefined", "symbol", "bigint", "object", "Array", "Function", "Promise"]
  }
}
  • 针对clean-jsdoc-theme主题关闭类型链接
    当前配置使用的是clean-jsdoc-theme模板,可直接在主题配置中关闭全局类型自动链接,在opts下新增theme_opts配置:
{
  "opts": {
    // 原有opts配置保留
    "theme_opts": {
      "link_for_types": false
    }
  }
}

如果使用的主题版本较旧配置不生效,可直接查找对应版本主题的配置项,关闭类型自动链接开关即可。

  • 单场景临时处理
    如果仅需要个别类型不生成链接,不需要全局修改配置,可以在注释的类型名两侧包裹反引号,JSDoc会将其识别为行内代码块,不会自动生成链接:
/**
 * the comment
 *
 * @param {`string`} myString
 */

内容的提问来源于stack exchange,提问作者Gravity123

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.27 23:10:00