Skip to content

Commit 519d91c

Browse files
committed
docs: add JSDoc explaining why BillingTransactionFn uses any
The callback parameter must use `any` because the real Drizzle transaction type (PgTransaction) has many additional properties (schema, rollback, etc.) that our minimal BillingDbConnection does not include. Using `any` allows both the real transaction and mock implementations to work together.
1 parent d9e9634 commit 519d91c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

common/src/types/contracts/billing.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,23 @@ export type BillingDbConnection = {
214214
/**
215215
* Transaction callback type.
216216
* This matches the signature of drizzle's db.transaction method.
217+
*
218+
* Note: The callback parameter uses `any` because the real Drizzle transaction
219+
* type (`PgTransaction`) has many additional properties (schema, rollback, etc.)
220+
* that our minimal `BillingDbConnection` doesn't include. Using `any` allows
221+
* both the real transaction and mock implementations to work.
222+
*
223+
* In tests, you can pass a mock that satisfies `BillingDbConnection`:
224+
* @example
225+
* ```typescript
226+
* const mockTransaction: BillingTransactionFn = async (callback) => {
227+
* const mockDb = createMockDb({ users: [...] })
228+
* return callback(mockDb)
229+
* }
230+
* ```
217231
*/
218232
export type BillingTransactionFn = <T>(
233+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
219234
callback: (tx: any) => Promise<T>,
220235
) => Promise<T>
221236

0 commit comments

Comments
 (0)