错误TS2304:找不到名称'RTCPeerConnection'

问题描述 投票:4回答:1

我在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个回答
5
投票

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

"types": [
  "webrtc"
]

到你的compilerOptionstypes选项被提及here

© www.soinside.com 2019 - 2024. All rights reserved.