解决方案:
在对应的属性(变量)上面添加type,给vscode提供类型支持,如下图所示:
/** @type {HTMLCanvasElement} */
/** @type {CanvasRenderingContext2D} */
如果是在HTML中,注释加在变量的上面
/** @type {HTMLCanvasElement} */
const canvas = document.getElementById('canvas')
thinking more... 使用这种方式我们可以给更多的变量或者属性添加代码提示,例如video元素