Open History to see the last commit
Type Alias: TransactionWithMutations<T, TOperation>#
type TransactionWithMutations<T, TOperation> = Omit<Transaction<T>, "mutations"> & object;
Defined in: packages/db/src/types.ts:142
Utility type for a Transaction with at least one mutation This is used internally by the Transaction.commit method
Type Declaration#
mutations#
mutations: NonEmptyArray<PendingMutation<T, TOperation>>;
We must omit the mutations property from Transaction<T> before intersecting
because TypeScript intersects property types when the same property appears on
both sides of an intersection.
Without Omit:
Transaction<T>hasmutations: Array<PendingMutation<T>>- The intersection would create:
Array<PendingMutation<T>> & NonEmptyArray<PendingMutation<T, TOperation>> - When mapping over this array, TypeScript widens
TOperationfrom the specific literal (e.g.,"delete") to the unionOperationType("insert" | "update" | "delete") - This causes
PendingMutation<T, OperationType>to evaluate the conditional typeoriginal: TOperation extends 'insert' ? {} : Tas{} | Tinstead of justT
With Omit:
- We remove
mutationsfromTransaction<T>first - Then add back
mutations: NonEmptyArray<PendingMutation<T, TOperation>> - TypeScript can properly narrow
TOperationto the specific literal type - This ensures
mutation.originalis correctly typed asT(not{} | T) when mapping
Type Parameters#
T#
T extends object = Record<string, unknown>
TOperation#
TOperation extends OperationType = OperationType