0

Hi i have the following method that i am trying to use

sendrequest(req: connreq) {
var promise = new Promise((resolve, reject) => {
  this.firereq.child(req.recipient).push({
  sender: req.sender
  }).then(() => {
    resolve({ success: true });
    }).catch((error) => {
      resolve(error);
})
})
return promise;  
}

But my visual studio code gives me the following error

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

I am using ionic to compile this program and i am unsure on how to correct this method. My tutorial is in ionic 3 so it may be old and i am not sure how to alter it to fit in to the new version.

Constantin Beer
  • 5,447
  • 6
  • 25
  • 43

1 Answers1

0

Avoid the Promise constructor antipattern! To convert something from a promise-like thing to a real promise, just use Promise.resolve:

sendrequest(req: connreq) {
  return Promise.resolve(this.firereq.child(req.recipient).push({
    sender: req.sender
  }));
}
Bergi
  • 630,263
  • 148
  • 957
  • 1,375