【问题标题】:error TS2304: Cannot find name 'RTCPeerConnection'错误 TS2304:找不到名称“RTCPeerConnection”
【发布时间】:2016-12-18 22:19:54
【问题描述】:

我在 Angular 2 中使用 WebRTC。

TypeScript 1.x中,我可以成功使用这个。

const peerConnection = new RTCPeerConnection(configuration, null);

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

错误 TS2304:找不到名称“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
  }
}

我怎样才能正确地做到这一点?

【问题讨论】:

    标签: angular typescript webrtc typescript2.0


    【解决方案1】:

    @types/webrtc 是一个全局类型定义。添加

    "types": [
      "webrtc"
    ]
    

    到您的compilerOptions。提到了types 选项here

    【讨论】:

      猜你喜欢
      • 2019-05-06
      • 2019-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-31
      • 1970-01-01
      相关资源
      最近更新 更多