【发布时间】:2021-11-23 21:04:26
【问题描述】:
我的代码是否有问题导致vscode 没有正确的提示?
/**
*
* @param {...Object} elementList
* @param {string} elementList[].type
*/
function add(...elementList) {
// vscode tip: elementList is (parameter) elementList: any[]
// expect: elementList is {type: string;}[]
elementList.map(e => e)
}
// use
add({ type: 'div' }, { type: 'h1' })
【问题讨论】:
-
是的,你实际上不能定义这样的参数的属性类型 (
elementList[].type)。据我所知,在 C 风格的语言(Java、JavaScript/TypeScript、C# 等)中,属性总是在其父声明中定义,例如type ElementList = { type: string }。点符号仅用于设置/获取,而不用于声明。
标签: visual-studio-code vscode-settings jsdoc jsdoc3