错误TS2304:找不到名称'RTCPeerConnection' [英] error TS2304: Cannot find name 'RTCPeerConnection'

查看:6
本文介绍了错误TS2304:找不到名称'RTCPeerConnection'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在角度2中使用WebRTC。

TypeScrip 1.x中,我可以成功使用它。

const peerConnection = new RTCPeerConnection(configuration, null);

但在更新到TypeScrip 2.x后,我在终端中收到以下错误:

错误TS2304:找不到名称‘RTCPeerConnection’。

我已将npm install --save-dev @types/webrtc链接到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

这篇关于错误TS2304:找不到名称'RTCPeerConnection'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆