我是一个离子初学者,并且正在学习一些教程,当我试图捕捉错误时,我遇到了一些打字稿问题......
'PromiseLike'类型中不存在属性'catch'
必须是过时的代码或其他内容。
问题出在哪里。它发生在我尝试使用catch的每个页面上。
.then(() => { resolve(true);})
.catch((err) => {reject(err);})
////////////////// UPDATE ////////// 这是package.json文件。我正在尝试创建一个firebase聊天应用程序。
{
"name": "chat",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "5.0.3",
"@angular/compiler": "5.0.3",
"@angular/compiler-cli": "5.0.3",
"@angular/core": "5.0.3",
"@angular/forms": "5.0.3",
"@angular/http": "5.0.3",
"@angular/platform-browser": "5.0.3",
"@angular/platform-browser-dynamic": "5.0.3",
"@ionic-native/core": "4.4.0",
"@ionic-native/file": "^4.4.2",
"@ionic-native/file-chooser": "^4.4.2",
"@ionic-native/file-path": "^4.4.2",
"@ionic-native/splash-screen": "4.4.0",
"@ionic-native/status-bar": "4.4.0",
"@ionic/storage": "2.1.3",
"angularfire2": "^5.0.0-rc.4",
"cordova-plugin-file": "^5.0.0",
"cordova-plugin-filechooser": "^1.0.1",
"cordova-plugin-filepath": "^1.1.0",
"firebase": "^4.7.0",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"rxjs": "5.5.2",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.18"
},
"devDependencies": {
"@ionic/app-scripts": "3.1.4",
"typescript": "2.4.2"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-file": {},
"cordova-plugin-filechooser": {},
"cordova-plugin-filepath": {}
}
}
}
答案 0 :(得分:2)
问题可能是因为"然后" on push返回一个ThenableReference,返回导致返回" PromiseLike"。相反,如果你选择使用"设置"在推,它将返回一个然后。所以这个方法应该是这样读的
let promise = new Promise((resolve, reject) => {
this.firerequest.child(request.recipient).push().set(
{ sender: request.sender }
).then(() => {
resolve({ success: true })
}).catch((error) => {
reject(error);
})
})
return promise;

您从Raja Yogan的聊天中摘录,所以我只是粘贴了其他提供商的代码。 希望能帮助到你。