0

I'm trying to return a promise with an .try(function(){}).catch(function(){}) block.
My problem is caused by the type of my promise.

    deleteProcess(processId: number): Promise<ProcessInstance> {
    let deletedProcess = this.Process.findById(processId);

    return Promise
        .try(function () {
            this.Process.destroy({
                where: {
                    processId: processId
                }
            })
                .then(function (rowDeleted) {
                    if (rowDeleted === 1) {
                        console.log('Deleted successfully');
                        return this.getDeletedProcess();
                    }
                })
                .catch(function (err) {
                    console.log(err);
                })
        });

    function getDeletedProcess(): ProcessInstance {
        return this.deletedProcess;
    };
};

The error says, that type 'Bluebird void' is not assignable to type 'Bluebird ProcessInstance'

James Monger
  • 10,181
  • 7
  • 62
  • 98
venter
  • 1,890
  • 2
  • 12
  • 15

1 Answers1

0

This post was really helpful to solve the problem

Bluebird.JS Promise: new Promise(function (resolve, reject){}) vs Promise.try(function(){})

This solves the problem:

    return new Promise<ProcessInstance>(
        (function (resolve, reject) {
            this.Process.destroy({
                where: {
                    processId: processId
                }
            })
                .then(function (rowDeleted) {
                    if (rowDeleted === 1) {
                        console.log('Deleted successfully');
                        return this.getDeletedProcess();
                    }
                })
                reject(function (err) {
                    console.log(err);
                })
        })
        )
Community
  • 1
  • 1
venter
  • 1,890
  • 2
  • 12
  • 15