The existing code forces the transaction to return a bluebird promise, which is incompatiable with es6 promises and async/await.

Thus if the user application is written in es6 promises with async/await, and have to return a bluebird promise in order to use bookshelf transactions, it becomes a burden to translate.
The bookshelf.transaction is an alias for knex.transaction(http://bookshelfjs.org/#Bookshelf-instance-transaction), and the knex.transaction uses any as a return type instead of promise.

I updated the return type of the user supplied function to PromiseLike, which both es6 and bluebird promises implement.

Tested with both bluebird and es6 promises.
This commit is contained in:
Steve Xian
2017-11-01 17:25:25 -07:00
parent b67c928904
commit 2373810e8d
+1 -1
View File
@@ -17,7 +17,7 @@ interface Bookshelf extends Bookshelf.Events<any> {
Collection: typeof Bookshelf.Collection;
plugin(name: string | string[] | Function, options?: any): Bookshelf;
transaction<T>(callback: (transaction: knex.Transaction) => BlueBird<T>): BlueBird<T>;
transaction<T>(callback: (transaction: knex.Transaction) => PromiseLike<T>): BlueBird<T>;
}
declare function Bookshelf(knex: knex): Bookshelf;