微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 jsDoc 3.6.6 记录函数表达式的内部方法 - Intellisense 有效但 jsdoc 无效

如何解决使用 jsDoc 3.6.6 记录函数表达式的内部方法 - Intellisense 有效但 jsdoc 无效

我想记录一些示例 Alexa SDK 代码中的函数表达式。 This person 似乎知道他们在做什么,除了 jsdoc linter 不喜欢这样的内联导入: @param {import('ask-sdk-core').HandlerInput} handlerInput

所以我只是在文件顶部使用了标准的 require 解决方法const { HandlerInput } = require('ask-sdk-core') 然后内联: @param {HandlerInput} handlerInput - blah

Intellisense 喜欢它,一切看起来都很棒...

enter image description here

除了 JSDOC 什么都没给我:

enter image description here

我似乎让 jsdoc 的所有其他方面都能完美运行,并且所有文档都非常漂亮。 除了这个。 我尝试将常量引用为几乎所有类型,搜索 github,阅读以下链接JSDoc not recognizing exported function JSDOC: How to document inner variables of function

这是我上面链接的示例代码的精简版。我错过了什么或做错了什么?任何想法表示赞赏。谢谢。

const { HandlerInput } = require('ask-sdk-core')

/** @constant */
const audioController = {
  /**
   * Handles the creation of a response with an AudioPlayerPlayDirective,relying on prevIoUsly set playbackInfo values. Also updates certain appSettings to maintain correct state of the skill.
   *
   * @param {HandlerInput} handlerInput - defined by Alexa
   * @returns {Promise<HandlerInput.Response>} alexa response object
   */
  async play (handlerInput) {
    const speakOutput = 'playing'
    return handlerInput.responseBuilder.speak(speakOutput).getResponse()
  },/**
   * Handles the creation of a response with an AudioPlayerStopDirective
   *
   * @param {HandlerInput} handlerInput - defined by Alexa
   * @returns {object} alexa response object
   */
  stop (handlerInput) {
    const speakOutput = 'stopping'
    return handlerInput.responseBuilder.speak(speakOutput).getResponse()
  }
}
module.exports = { audioController }

解决方法

感谢@customcommander 的指导,我找到了 this Q&A,它为我指明了以下解决方案。不幸的是,虽然 jsdoc 没有问题,但 VSCode 智能感知不会“看到”单独文件中的命名空间定义。

似乎 jsdoc 不要求 @memberof,但据我所知,这是一种很好的做法(?),并且没有害处。非常感谢您的帮助。

/**
 * Audiocontroller namespace
 *
 * @namespace audioController
 */
const audioController = {
  /**
   * Handles the creation of a response with an AudioPlayerPlayDirective
   *
   * @param {HandlerInput} handlerInput - defined by Alexa
   * @memberof audioController
   * @returns {object} alexa response object
   */
  async play (handlerInput) {
    const speakOutput = 'playing'
    return handlerInput.responseBuilder.speak(speakOutput).getResponse()
  },/**
   * Handles the creation of a response with an AudioPlayerStopDirective
   *
   * @param {HandlerInput} handlerInput - defined by Alexa
   * @memberof audioController
   * @returns {object} alexa response object
   */
  stop (handlerInput) {
    const speakOutput = 'stopping'
    return handlerInput.responseBuilder.speak(speakOutput).getResponse()
  }
}

module.exports = { audioController }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。