问题描述
我想记录一些示例 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 喜欢它,一切看起来都很棒...
除了 JSDOC 什么都没给我:
我似乎让 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 }