簡體   English   中英

嘗試使用 tsc file.ts 運行 Typescript 時出現 WebGL2RenderingContext 錯誤

[英]WebGL2RenderingContext Error when trying to run Typescript with tsc file.ts

我剛剛在我的 Windows 10 機器上使用 npm 和 yarn 安裝了 Typescript,當我運行“tsc file.ts”時,我收到一條錯誤消息,顯示“582 declare var WebGL2RenderingContext”。

它指向目錄 ../../AppData/Roaming/npm/node_modules/typescript/lib/lib.dom.d.ts:16485:13

此外,它說 16485 聲明 var WebGL2RenderingContext: { 'WebGL2RendingContext' 也在此處聲明。 發現 1 個錯誤。

這是來自 Node.js 命令提示符的截圖

在此處輸入圖片說明

我解決了執行此行的問題。

npm i --save @types/webgl2

如果您的聲明發生沖突,請嘗試導入您需要的聲明:

import {WebGL2RenderingContext} from "webgl2"
const lol = (ctx: WebGL2RenderingContext)=>{/* do sth*/};

@types/webgl2 的問題是它沒有導出,所以你必須稍微改變它:只需在declare關鍵字之前添加導出。

沒有 Zydnar 的幫助,我無法解決這個問題,感謝他。 經過一番深思熟慮,我決定注釋掉 WebGL2 渲染函數,它起作用了,它轉譯為 javascript,最后我使用 ts-node filename.ts 來運行代碼。

再次感謝@Zydnar,你很有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM