错误 TS2339:属性 'catch' 在类型 'PromiseLike<void>' 上不存在
error TS2339: Property 'catch' does not exist on type 'PromiseLike<void>'
我在 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
:
error TS2339: Property 'catch' does not exist on type
'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 是和他们一样,只是有更多的包裹。
我怎样才能摆脱这个错误?
内置库 dom
声明了导致定义的问题(参见 lib.dom.d.ts):
getUserMedia(constraints: MediaStreamConstraints): PromiseLike<MediaStream>;
而 @types/webrtc
声明了您预期的定义(参见 MediaStream.d.ts):
getUserMedia(constraints: MediaStreamConstraints): Promise<MediaStream>;
TypeScript 存储库中有一个 open issue。
我在 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
:
error TS2339: Property 'catch' does not exist on type '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 是和他们一样,只是有更多的包裹。
我怎样才能摆脱这个错误?
内置库 dom
声明了导致定义的问题(参见 lib.dom.d.ts):
getUserMedia(constraints: MediaStreamConstraints): PromiseLike<MediaStream>;
而 @types/webrtc
声明了您预期的定义(参见 MediaStream.d.ts):
getUserMedia(constraints: MediaStreamConstraints): Promise<MediaStream>;
TypeScript 存储库中有一个 open issue。