我正在尝试返回一个带有.try(function(){}).catch(function(){})块的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;
};
};错误说明,类型'Bluebird void‘不能赋值给类型'Bluebird ProcessInstance’
发布于 2016-10-31 20:34:26
这篇文章确实对解决这个问题很有帮助。
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);
})
})
)https://stackoverflow.com/questions/40340633
复制相似问题