在我的Angular 2项目中,我尝试使用typescript和@types/webrtc。@types/webrtc的版本是0.0.21,如果我使用高于2.1.5的typescript版本,我会收到很多webrtc的编译错误。
这是我的package.json文件:
{
"name": "d3",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"start": "ng serve",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/cli": "1.0.3",
"@angular/common": "4.1.2",
"@angular/animations": "4.1.2",
"@angular/compiler": "4.1.2",
"@angular/compiler-cli":"4.1.2",
"@angular/core": "4.1.2",
"@angular/forms": "4.1.2",
"@angular/http": "4.1.2",
"@angular/platform-browser": "4.1.2",
"@angular/platform-browser-dynamic": "4.1.2",
"@angular/router": "4.1.2",
"@angular/material": "2.0.0-beta.5",
"@types/hammerjs": "2.0.34",
"hammerjs": "2.0.8",
"angular2-material-datepicker": "0.5.0",
"core-js": "2.4.1",
"primeng": "4.0.1",
"rxjs": "5.4.0",
"ts-helpers": "1.1.2",
"zone.js": "0.8.10"
},
"devDependencies": {
"@types/jasmine": "2.5.47",
"@types/node": "7.0.18",
"@types/webrtc": "0.0.21",
"angular2-template-loader": "0.6.2",
"codelyzer": "3.0.1",
"jasmine-core": "2.6.1",
"jasmine-spec-reporter": "4.1.0",
"karma": "1.7.0",
"karma-chrome-launcher": "2.1.1",
"karma-cli": "1.0.1",
"karma-jasmine": "1.1.0",
"karma-remap-istanbul": "0.6.0",
"protractor": "5.1.2",
"ts-node": "3.0.4",
"tslint": "5.2.0",
"typescript": "2.3.2",
"webdriver-manager": "12.0.6"
}
}以下是编译错误:
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (31,6): Duplicate identifier 'RTCSdpType'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (35,5): All declarations of 'type' must have identical modifiers.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (41,14): All declarations of 'type' must have identical modifiers.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (42,14): All declarations of 'sdp' must have identical modifiers.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (49,6): Duplicate identifier 'RTCIceProtocol'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (52,6): Duplicate identifier 'RTCIceCandidateType'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (55,6): Duplicate identifier 'RTCIceTcpCandidateType'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (59,5): All declarations of 'candidate' must have identical modifiers.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (66,14): All declarations of 'candidate' must have identical modifiers.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (67,14): All declarations of 'sdpMid' must have identical modifiers.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (68,14): All declarations of 'sdpMLineIndex' must have identical modifiers.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (90,6): Duplicate identifier 'RTCSignalingState'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (93,6): Duplicate identifier 'RTCIceGatheringState'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (96,6): Duplicate identifier 'RTCIceConnectionState'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (113,6): Duplicate identifier 'RTCIceTransportPolicy'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (116,6): Duplicate identifier 'RTCBundlePolicy'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (122,6): Duplicate identifier 'RTCIceRole'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (125,6): Duplicate identifier 'RTCIceComponent'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (128,6): Duplicate identifier 'RTCIceTransportState'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (153,6): Duplicate identifier 'RTCDtlsTransportState'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (204,5): All declarations of 'maxFramerate' must have identical modifiers.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (231,6): Duplicate identifier 'RTCDegradationPreference'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (401,6): Duplicate identifier 'RTCSessionDescriptionCallback'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (405,6): Duplicate identifier 'RTCPeerConnectionErrorCallback'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (409,6): Duplicate identifier 'RTCStatsCallback'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (432,14): All declarations of 'canTrickleIceCandidates' must have identical modifiers.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (438,5): Subsequent variable declarations must have the same type. Variable 'onnegotiationneeded' must be of type '(this: RTCPeerConnection, ev: Event) => any', but here has type 'EventHandler'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (439,5): Subsequent variable declarations must have the same type. Variable 'onicecandidate' must be of type '(this: RTCPeerConnection, ev: RTCPeerConnectionIceEvent) => any', but here has type '(event: RTCPeerConnectionIceEvent) => void'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (441,5): Subsequent variable declarations must have the same type. Variable 'onsignalingstatechange' must be of type '(this: RTCPeerConnection, ev: Event) => any', but here has type 'EventHandler'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (442,5): Subsequent variable declarations must have the same type. Variable 'oniceconnectionstatechange' must be of type '(this: RTCPeerConnection, ev: Event) => any', but here has type 'EventHandler'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (443,5): Subsequent variable declarations must have the same type. Variable 'onicegatheringstatechange' must be of type '(this: RTCPeerConnection, ev: Event) => any', but here has type 'EventHandler'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (491,13): Subsequent variable declarations must have the same type. Variable 'RTCPeerConnection' must be of type '{ new (configuration: RTCConfiguration): RTCPeerConnection; prototype: RTCPeerConnection; }', but here has type 'RTCPeerConnectionStatic'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (492,13): Subsequent variable declarations must have the same type. Variable 'RTCSessionDescription' must be of type '{ new (descriptionInitDict?: RTCSessionDescriptionInit): RTCSessionDescription; prototype: RTCSes...', but here has type 'RTCSessionDescriptionStatic'.
ERROR in objs/node_modules/@types/webrtc/RTCPeerConnection.d.ts (493,13): Subsequent variable declarations must have the same type. Variable 'RTCIceCandidate' must be of type '{ new (candidateInitDict?: RTCIceCandidateInit): RTCIceCandidate; prototype: RTCIceCandidate; }', but here has type 'RTCIceCandidateStatic'.
ERROR in objs/node_modules/@types/webrtc/MediaStream.d.ts (104,14): Duplicate identifier 'MediaStreamTrackState'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (834,5): All declarations of 'candidate' must have identical modifiers.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (995,5): All declarations of 'maxFramerate' must have identical modifiers.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (1040,5): All declarations of 'type' must have identical modifiers.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (9048,5): All declarations of 'candidate' must have identical modifiers.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (9049,5): All declarations of 'sdpMLineIndex' must have identical modifiers.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (9050,5): All declarations of 'sdpMid' must have identical modifiers.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (9147,14): All declarations of 'canTrickleIceCandidates' must have identical modifiers.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (9241,5): All declarations of 'sdp' must have identical modifiers.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (9242,5): All declarations of 'type' must have identical modifiers.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (14254,11): Duplicate identifier 'RTCSessionDescriptionCallback'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (14257,11): Duplicate identifier 'RTCPeerConnectionErrorCallback'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (14260,11): Duplicate identifier 'RTCStatsCallback'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (15011,6): Duplicate identifier 'MediaStreamTrackState'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (15023,6): Duplicate identifier 'RTCBundlePolicy'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (15024,6): Duplicate identifier 'RTCDegradationPreference'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (15026,6): Duplicate identifier 'RTCDtlsTransportState'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (15027,6): Duplicate identifier 'RTCIceCandidateType'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (15028,6): Duplicate identifier 'RTCIceComponent'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (15029,6): Duplicate identifier 'RTCIceConnectionState'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (15032,6): Duplicate identifier 'RTCIceGatheringState'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (15033,6): Duplicate identifier 'RTCIceProtocol'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (15034,6): Duplicate identifier 'RTCIceRole'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (15035,6): Duplicate identifier 'RTCIceTcpCandidateType'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (15036,6): Duplicate identifier 'RTCIceTransportPolicy'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (15037,6): Duplicate identifier 'RTCIceTransportState'.
ERROR in objs/node_modules/typescript/lib/lib.dom.d.ts (15038,6): Duplicate identifier 'RTCSdpType'.发布于 2017-08-04 19:11:10
目前还没有正式的解决方案(或者,至少我还没有找到)。但是有一个很好的变通方法,它可以让你继续工作!
正如你在DefinitelyTyped Github web的issue中看到的,Varius建议在你的tsconfig.json中添加一个比compilerOptions更好的选项,以避免库检查。
"compilerOptions": {
"skipLibCheck": true
}我希望它也适用于你,它也适用于我!
发布于 2018-01-15 22:31:38
在您的tsconfig.json中添加以下内容:
{
"compilerOptions": {
"typeRoots": [
"node_modules/@types"
],
}https://stackoverflow.com/questions/44005415
复制相似问题