javascript 的 VSCode 智能感知不适用于 Canvas 元素

Ḉớᶑ*_*ꞣǐɱ 3 javascript canvas

VScode 智能感知在 HTML 5“canvas”元素上工作是否存在问题?Intellisense 不提供自动完成支持

var canvas = document.getElementById("canvas")
canvas.getC... /*there is no .getContext("2d")*/

Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

小智 9

使用 JSDoc@type获取canvas元素:

/** @type {HTMLCanvasElement} */
const c = document.getElementById('canvas');
Run Code Online (Sandbox Code Playgroud)

查看更多:在 HTML Canvas 的 VS Code 中获取 IntelliSense作者:Nathan Vaughn