加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 错误TS2304:找不到名称’RTCPeerConnection’

发布时间:2020-12-17 17:26:49 所属栏目:安全 来源:网络整理
导读:我在Angular 2中使用WebRTC. 在TypeScript 1.x中,我可以成功使用它. const peerConnection = new RTCPeerConnection(configuration,null); 但在更新到TypeScript 2.x后,我的终端出现了这个错误: error TS2304: Cannot find name ‘RTCPeerConnection’. 我
我在Angular 2中使用WebRTC.

在TypeScript 1.x中,我可以成功使用它.

const peerConnection = new RTCPeerConnection(configuration,null);

但在更新到TypeScript 2.x后,我的终端出现了这个错误:

error TS2304: Cannot find name ‘RTCPeerConnection’.

我已经安装了npm install –save-dev @ types / webrtc,我的IDE WebStorm已经正确地将它链接到RTCPeerConnection的输入.

RTCPeerConnection的输入位于/my-project/node_modules/@types/webrtc/RTCPeerConnection.d.ts中

我的tsconfig.json文件:

{
  "compilerOptions": {
    "emitDecoratorMetadata": true,"experimentalDecorators": true,"target": "es5","module": "commonjs","removeComments": true,"sourceMap": true,"lib": ["es6","dom"]
  },"include": [
    "node_modules/@types/**/*.d.ts","src/**/*.ts"
  ],"exclude": [
    "node_modules","!node_modules/@types/**/*.d.ts"
  ],"compileOnSave": false,"buildOnSave": false,"atom": {
    "rewriteTsconfig": false
  }
}

我该怎么做才能正确?

解决方法

@ types / webrtc是全局类型定义.加

"types": [
  "webrtc"
]

你的compilerOptions.类型选项提到here.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读