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

前端之家收集整理的这篇文章主要介绍了angular – 错误TS2304:找不到名称’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.

猜你在找的Angularjs相关文章