admin管理员组文章数量:1312656
Is there a problem with VScode intellisense to work on HTML 5 'canvas' element. Intellisense doesn't provide auto pletion support
var canvas = document.getElementById("canvas")
canvas.getC... /*there is no .getContext("2d")*/
Is there a problem with VScode intellisense to work on HTML 5 'canvas' element. Intellisense doesn't provide auto pletion support
var canvas = document.getElementById("canvas")
canvas.getC... /*there is no .getContext("2d")*/
Share
Improve this question
asked Sep 19, 2020 at 16:19
Ḉớᶑẽr ĦậꞣǐɱḈớᶑẽr Ħậꞣǐɱ
1901 silver badge7 bronze badges
4
- 1 Intellisense doesn't work well for JavaScript because of its prototype-based inheritance. – FlatAssembler Commented Sep 19, 2020 at 16:22
-
1
All it can know is that
getElementById()
will return a reference to an element node. It cannot predict that the element found will be a<canvas>
element. – Pointy Commented Sep 19, 2020 at 16:25 - @Pointy That's no excuse, if a human being can do it, software can do too. – BEIC Commented Sep 26, 2020 at 8:32
-
@BEIC well if you have some ideas on how such a facility could be implemented, allowing a code editor to know what type of element a call to
.getElementById()
will return, you can create a peting tool to VSCode. – Pointy Commented Sep 26, 2020 at 12:25
2 Answers
Reset to default 12Use JSDoc @type
with getting canvas
element:
/** @type {HTMLCanvasElement} */
const c = document.getElementById('canvas');
See more: Get IntelliSense in VS Code for HTML Canvas by Nathan Vaughn
You can also do this. Remove the canvas from HTML, and add it dynamically using javascript code.
let canvas = document.createElement("canvas");
let ctx = canvas.getContext("2d");
document.body.appendChild(canvas);
本文标签: VSCode intellisense for javascript not working for Canvas elementStack Overflow
版权声明:本文标题:VSCode intellisense for javascript not working for Canvas element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741912804a2404545.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论