filipbarak
filipbarak

Reputation: 1905

Property then doesn't exist on type void, although I am returning a Promise

I have a function that gets a bot's inventory on the Frontend

  getBotInventory() {
    this.socket.emit('get bot inv');
    this.socket.on('bot inv', (botInventory) => {
      return new Promise((resolve, reject) => {
        if (botInventory.error) {
          return reject(botInventory.error);
        }
        this.botInventory = botInventory;
        resolve(botInventory);
      });

    });
  }

As you can see, it returns a Promise.

When I try to call it

getBotInventory() {
    this.userService.getBotInventory().then(botInv..)
  }

I'm getting

error TS2339: Property 'then' does not exist on type 'void'.

Obviously it returns a Promise. Can anyone point out where the problem is?

Upvotes: 3

Views: 4045

Answers (1)

user4676340
user4676340

Reputation:

It may be obvious for you, but it isn't for me.

Look at your function, cleaned of callbacks.

getBotInventory() {
  this.socket.emit('get bot inv');
  this.socket.on('bot inv', (botInventory) => {...});
}

I don't see any return statement there !

Upvotes: 5

Related Questions