据我所知,VS Code已经支持TypeScript和JavaScript中的类型注释,但是在VS Code无法正确理解引用者的情况下,如何启用它或将其正确用于内联变量?
这是我的代码:
export const TooltipModule = {
init() {
this.tooltipelements = document.getElementsByClassname('tooltip')
if (this.tooltipelements.length > 0) {
this.enableTooltips()
}
},enableTooltips() {
/** @var {Element} tp */
for (const tp of this.tooltipelements) {
new Tooltip(tp /* no type annotation here */,{
placement: 'bottom',title: 'Top',})
}
},}
我也尝试使用@type
或@param
。