在JS中获取canvas元素前写上如下代码即可
/** @type {HTMLCanvasElement} */
let canvas = document.querySelector('#canvas')