[英]WebGL2RenderingContext Error when trying to run Typescript with tsc file.ts
I just installed Typescript using both npm and yarn on my Windows 10 machine, and when I run 'tsc file.ts' I get an error that says '582 declare var WebGL2RenderingContext'.我刚刚在我的 Windows 10 机器上使用 npm 和 yarn 安装了 Typescript,当我运行“tsc file.ts”时,我收到一条错误消息,显示“582 declare var WebGL2RenderingContext”。
It directs to the directory ../../AppData/Roaming/npm/node_modules/typescript/lib/lib.dom.d.ts:16485:13它指向目录 ../../AppData/Roaming/npm/node_modules/typescript/lib/lib.dom.d.ts:16485:13
Furthermore, It says 16485 declare var WebGL2RenderingContext: { 'WebGL2RendingContext'was also declared here.此外,它说 16485 声明 var WebGL2RenderingContext: { 'WebGL2RendingContext' 也在此处声明。 Found 1 error.
发现 1 个错误。
Here is the screeshot from Node.js Command Prompt这是来自 Node.js 命令提示符的截图
我解决了执行此行的问题。
npm i --save @types/webgl2
If your declarations collide try to import declaration you need:如果您的声明发生冲突,请尝试导入您需要的声明:
import {WebGL2RenderingContext} from "webgl2"
const lol = (ctx: WebGL2RenderingContext)=>{/* do sth*/};
with @types/webgl2 problem is it have no exports, so you have to change it a bit: just add export before declare
keywords. @types/webgl2 的问题是它没有导出,所以你必须稍微改变它:只需在
declare
关键字之前添加导出。
I could not have solved this problem without Zydnar's Help, Thanks to Him.没有 Zydnar 的帮助,我无法解决这个问题,感谢他。 After some deliberation, I decided to comment out the WebGL2 Rendering Function and It worked, It transpiled to javascript and I ended up using ts-node filename.ts to run the code.
经过一番深思熟虑,我决定注释掉 WebGL2 渲染函数,它起作用了,它转译为 javascript,最后我使用 ts-node filename.ts 来运行代码。
Thanks once again to @Zydnar, You were very helpful.再次感谢@Zydnar,你很有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.