【发布时间】:2016-08-14 04:55:29
【问题描述】:
我在 Angular 2 中使用 WebRTC。
在TypeScript 1.x中,我可以成功使用这个。
navigator.mediaDevices.getUserMedia(constraints)
.then(myStream => {
this.myStream = myStream;
})
.catch(error => {
console.log(error);
});
但更新到 TypeScript 2.x 后,我在终端运行 npm run watch 时出现此错误:
错误 TS2339:类型上不存在属性“catch” 'PromiseLike'。
我的 IDE WebStore 也显示为红色:
我已经做了npm install --save-dev @types/webrtc。
我的 tsconfig.json 文件:
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"module": "commonjs",
"removeComments": true,
"sourceMap": true,
"lib": ["es6", "dom"],
"types": [
"body-parser",
"compression",
"express",
"express-session",
"mime",
"node",
"serve-static",
"webrtc",
"ws"
]
},
"include": [
"node_modules/@types/**/*.d.ts",
"src/**/*.ts"
],
"exclude": [
"node_modules",
"!node_modules/@types/**/*.d.ts"
],
"compileOnSave": false,
"buildOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
我使用universal-starter作为开始,所以我的nodemon.json和package.json和他们一样,只是有更多的包。
我怎样才能摆脱这个错误?
【问题讨论】:
-
getUserMedia返回什么? -
@torazaburo 它返回
Promise<MediaStream> -
@HongboMiao 请发布完整的错误消息(带有调用堆栈)。如果我运行您的示例,我将无法重现此错误。
getUserMedia.then在我的设置中返回Promise而不是PromiseLike。因此,我没有收到错误。此错误是否出现在您的“真实代码”中的不同位置,或者您是否使用此确切代码收到此错误? -
@HongboMiao 请发布您的tsconfig.json。
标签: angular typescript promise getusermedia typescript2.0