angular - 错误 TS2304 : Cannot find name 'RTCPeerConnection'

标签 angular typescript webrtc typescript2.0

我在 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。提到了 types 选项 here .

关于angular - 错误 TS2304 : Cannot find name 'RTCPeerConnection' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38908860/

相关文章:

angular - ViewChild 和 focus()

javascript - 在 angular2 中找不到 json 文件

angular - tslint 错误阴影名称 : 'Observable'

c++ - 为什么 webrtc 找不到它建议的捕获器?

javascript - 用户登录时更新所有用户相关数据(可观察)

angular - 如何在 Angular 7 的页面加载时打开 ng-bootstrap 模式弹出窗口?

angular - 如何在 Angular 2 中使用 "chain"两个单独的可观察对象

html - 无法通过 btn-group open 打开下拉按钮组

javascript - 我在检查器 "This file is a template and if you open it directy in the browser you will see an empty page."中看到一个空页面和此消息

video-streaming - 可以在服务器端使用 WebRTC 来获取流帧吗?