jsdoc


类型注释 https://jsdoc.app/

/**
 * @param  {number} a param1
 * @param  {number} b param2
 * @returns {number} 
 * */
function fn(a, b) {
    return a + b
}

let a = fn()

常见的类型注释

  • @type 变量类型
  • @param(或@params@argument) 参数类型
  • returns(或returns) 返回值类型
  • typedef 相当于ts中的type Status = "open" | "close"
  • @callback 回调函数 https://jsdoc.app/tags-callback.html
  • @template
  • @class@constructor
  • @this 函数内部this指向
  • @extends(@arguments)
  • enum
/**@typedef {'open'|'close'} Status */

/**@type {Status} */
const a = 'close'

在webpack中使用

/** @type {import('webpack').Configuration} */
module.exports = {
    ...
}

文章作者: Shibin
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Shibin !
  目录