错误TS2304:找不到名称';RTCPeerConnection'; [英] error TS2304: Cannot find name 'RTCPeerConnection'
本文介绍了错误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屋!
查看全文