gpt4 book ai didi

angular - 类型 'catch' 上不存在属性 'PromiseLike'

转载 作者:太空狗 更新时间:2023-10-29 18:30:15 26 4
gpt4 key购买 nike

我是一个 ionic 初学者,正在学习一些教程,当我试图捕捉一个错误时,我遇到了一些 typescript 问题......

Property 'catch' does not exist on type 'PromiseLike'

一定是过时的代码之类的。

问题就在这里。它发生在我尝试使用 catch 的每个页面上。

.then(() => { resolve(true);})
.catch((err) => {reject(err);})

Here is a screenshot

Here is another screenshot

/////////////////更新//////////这是 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": {}
}
}
}

最佳答案

这个问题可能是因为推送时的“then”返回了一个 ThenableReference,它反过来导致返回一个“PromiseLike”。相反,如果您选择在推送时使用“set”,它将返回 then。所以这个方法应该是这样的

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 的聊天记录,所以我只是粘贴了来自不同提供商的代码。希望能帮助到你。

关于angular - 类型 'catch' 上不存在属性 'PromiseLike<void>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47659996/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com