Explain what kind of behaviour you are getting and how you think it should do
I found a mismatch between runtime behavior and TypeScript typings for transactions when trx.commit(value) is called inside a transaction callback.
Runtime behavior:
const trRes = await knex.transaction(async (trx) => {
const result = await trx.raw('SELECT 1 + 1 AS result');
await trx.commit(true);
return result;
});
// trRes is true (boolean), not `result`
So the transaction resolves with the value passed to commit(...), even if callback later returns something else.
Current typings suggest knex.transaction(...) resolves by callback return T, which is misleading in this pattern.
Also, current typings for trx.commit/trx.rollback do not appear to reflect their actual runtime shape.
Expected:
- Either typings should better model this behavior where possible, and/or
- docs should explicitly warn that manual trx.commit(value) inside callback can override callback return value for final transaction result.
Error message
No runtime error; this is a behavioral + typing inconsistency.
Notes for potential fix
- TypeScript updates in types/index.d.ts via Generics,
- docs clarification in /docs (transactions guide),
- and link the corresponding docs PR in the main PR description.
Explain what kind of behaviour you are getting and how you think it should do
I found a mismatch between runtime behavior and TypeScript typings for transactions when
trx.commit(value)is called inside a transaction callback.Runtime behavior:
So the transaction resolves with the value passed to commit(...), even if callback later returns something else.
Current typings suggest knex.transaction(...) resolves by callback return T, which is misleading in this pattern.
Also, current typings for trx.commit/trx.rollback do not appear to reflect their actual runtime shape.
Expected:
Error message
No runtime error; this is a behavioral + typing inconsistency.
Notes for potential fix