我试图用.try(function(){}).catch(function(){})
块来回复承诺。
我的问题是由我的承诺类型引起的。
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;
};
};
错误说,那种类型&#39; Bluebird无效&#39;不能分配给&#39; Bluebird ProcessInstance&#39;
答案 0 :(得分:0)
此帖非常有助于解决问题
Bluebird.JS Promise: new Promise(function (resolve, reject){}) vs Promise.try(function(){})
这解决了这个问题:
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);
})
})
)