简体   繁体   English

&#39;PromiseLike&#39;类型中不存在属性&#39;catch&#39; <void> “

[英]Property 'catch' does not exist on type 'PromiseLike<void>'

Im an ionic beginner and was following some tutorials and as I was trying to catch an error I ran into some typescript problems... 我是一个离子初学者,并正在遵循一些教程,因为我试图捕捉到一个错误,我遇到了一些打字稿问题......

Property 'catch' does not exist on type 'PromiseLike' 'PromiseLike'类型中不存在属性'catch'

Must be an outdated code or something. 必须是过时的代码或其他东西。

Here where the problem is. 这是问题所在。 It happens to every page I try to use the catch. 它发生在我尝试使用catch的每个页面上。

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

这是一个截图

这是另一个截图

//////////////////UPDATE////////// Here is the package.json file. ////////////////// UPDATE //////////这是package.json文件。 Im trying to create a firebase chat app. 我试图创建一个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": {}
    }
  }
}

The issue is probably because the "then" on push returns a ThenableReference which in return causes to return a "PromiseLike". 问题可能是因为push上的“then”返回一个ThenableReference,返回导致返回“PromiseLike”。 Instead, if you choose to use "set" on push, it will return a then. 相反,如果你选择在push上使用“set”,它将返回一个then。 So the method should read like this 所以该方法应该是这样的

 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; 

Your excerpt from Raja Yogan's chat, so I just pasted code from a different provider. 您摘自Raja Yogan的聊天,所以我只是粘贴了来自不同提供商的代码。 Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM