2016-08-12 81 views
3

我使用的WebRTC在打字稿1.x中,我可以成功地使用这个。错误TS2304:不能在角2</p> <p>找到名为“RTCPeerConnection”

const peerConnection = new RTCPeerConnection(configuration, null); 

但更新到打字稿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 
    } 
} 

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

回答

4

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

"types": [ 
    "webrtc" 
] 

到您的compilerOptionstypes选项被提及here

+0

谢谢,作品完美! –

相关问题