【问题标题】:JSDoc comments not showing on absolute path importJSDoc 注释未显示在绝对路径导入上
【发布时间】:2020-01-15 20:49:19
【问题描述】:

我正在添加 JSDoc 函数文档,但在导入具有绝对页面路径的函数时无法显示我的文档 cmets。

JSDoc函数:

/**
* Adds two numbers together and returns that value
* @param {number} a
* @param {number} b
* @return {number} returns the value of a plus b
*/
function addNums (a, b) {
 return a + b;
}

export { addNums }

适用于相对页面路径:

import { addNums } from './addNums'

不适用于绝对页面路径:

import { addNums } from '~/lib/helpers/addNums'

当我在实际代码中将路径从绝对路径更改为相对路径时的屏幕截图:

绝对页面路径: 相对页面路径: 我已经尝试过这个 SO 线程中列出的解决方案:How do I get VSCode to recognize current package Javascript imports?

不幸的是,这不起作用,所以我想知道如何让 JSDoc 识别我的绝对页面路径,而不是我在导入时定义的相对页面路径。谢谢!

【问题讨论】:

    标签: javascript import visual-studio-code jsdoc


    【解决方案1】:

    想通了。所以这是我们配置 webpack 以识别 ~ 的方式的问题

    //webpack config
    
         config.resolve.alias = {
          ...config.resolve.alias,
          '~': path.resolve(__dirname)
        }
    

    我相信通常 JSdoc 在解析绝对文件路径时没有问题,但就我而言,我添加了一个 tsconfig.json 文件:

       ///tsconfig.json
    
       {
        "compilerOptions": {
            "allowJs": true,
            "baseUrl": ".",
            "paths": {
                "~/*": ["*"]
            }
        }
    }
    

    这成功了。如果这让其他人感到困惑,请道歉,直到这篇文章之后我才知道 webpack 配置,但很有可能其他人有类似的配置并试图让 JSDoc 工作,这就是解决方案!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-02
      • 1970-01-01
      • 2017-04-20
      • 2020-10-19
      • 1970-01-01
      • 2021-04-13
      相关资源
      最近更新 更多