简体   繁体   中英

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'.

It directs to the directory ../../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. Found 1 error.

Here is the screeshot from Node.js Command Prompt

在此处输入图片说明

我解决了执行此行的问题。

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.

I could not have solved this problem without Zydnar's Help, Thanks to Him. 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.

Thanks once again to @Zydnar, You were very helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM