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 errors… Here is my code.

addnewmessage(msg) {
    if (this.buddy) {
      var promise = new Promise((resolve, reject) => {
        this.firebuddychats.child(firebase.auth().currentUser.uid).child(this.buddy.uid).push({
          sentby: firebase.auth().currentUser.uid,
          message: msg,
          timestamp: firebase.database.ServerValue.TIMESTAMP
        }).then(() => {
          this.firebuddychats.child(this.buddy.uid).child(firebase.auth().currentUser.uid).push({
            sentby: firebase.auth().currentUser.uid,
            message: msg,
            timestamp: firebase.database.ServerValue.TIMESTAMP
          }).then(() => {
            resolve(true);
            }).catch((err) => {
              reject(err);
          })
        })
      })
      return promise;
    }
  }

and screenshots

It might sound crazy, but don’t do this. There are a ton of misleading tutorials on the web. Sometimes written by people who don’t code well, but most of the time the issue is that the framework has changed so much, old tutorials are out of date, but they still look good.

Same thing is true about Firebase. When you’re looking at out of date information for both Ionic and Firebase, watch out.

Read the official documentation for AngularFire2, version 5. There’s an Ionic example. Big picture: the Angular documentation is excellent, the AngularFire2 documentation is very good, the Ionic documentation is not bad, and a lot of tutorials are dangerous.

2 Likes