我收到文件node_modules/@types/webrtc/index.d.ts不是带有此代码的模块:
import * as webrtc from "webrtc";
const peerConnection1 = new RTCPeerConnection();
Run Code Online (Sandbox Code Playgroud)
我已经安装了打字机npm i @types/webrtc --save-dev.将鼠标悬停在Visual Studio代码RTCPeerConnection中的const peerConnection1 = new RTCPeerConnection();显示类型注释中,以便至少代码编辑器可以看到类型.运行tsc(或webpackwith ts-loader)失败并显示错误.
我试图npm i webrtc --save以误导的方式解决这个问题,但它没有改变任何东西,我真的只想要打字,WebRTC就在浏览器中,我不需要一个包.(支持旁边.)
该index.d.ts文件确实不是一个模块,它只引用其中包含接口的其他两个文件.所以我想删除import * as webrtc from "webrtc";希望打字仍然可以以tsc某种方式显示.(但这是不可能的,因为我node_modules在TypeScript配置文件中排除.)当我这样做时,RTCPeerConnection不再被识别.
添加/// <reference src="node_modules/@types/webrtc/" />没有帮助,tsc说无效的引用指令语法.
您可以在GitLab上查看具有最少repro的存储库.我不太熟悉TypeScript打字收购,所以请原谅我的无知,如果我说这一切都错了.