我的代码是File node_modules/@types/webrtc/index.d.ts is not a module:
import * as webrtc from "webrtc";
const peerConnection1 = new RTCPeerConnection();
我用npm i @types/webrtc --save-dev
台 typewriter 安装了 typewriter .将鼠标悬停在Visual Studio代码中的RTCPeerConnection
/const peerConnection1 = new RTCPeerConnection();
显示类型注释上,这样至少代码编辑器可以看到这些类型.运行tsc
(或webpack
和ts-loader
)失败,出现错误.
为了解决这个问题,我try 了npm i webrtc --save
次错误的try ,但它没有改变任何东西,我真的只想要打字,不管怎样,WebRTC就在浏览器中,我不需要一个软件包.(支持除外.)
index.d.ts
文件实际上不是一个模块,它只是引用了另外两个文件,其中包含接口.所以我想go 掉import * as webrtc from "webrtc";
,希望tsc
还能看到打字.(但这是不可能的,因为我在TypeScript配置文件中排除了node_modules
.)当我这么做的时候,RTCPeerConnection
就不再被认出来了.
tsc
表示,增加/// <reference src="node_modules/@types/webrtc/" />
没有帮助.
您可以使用最少的repo here on GitLab查看存储库.我不太擅长打字,所以如果我在这方面完全错了,请原谅我的无知.