本页还没有译文
本页 17 段还没译成Español,下面显示的是英文原文。TransactionWithMutations
还没翻译译自英文(tanstack.com)本页 17 段都还没译
type TransactionWithMutations<T, TOperation, TCollection> = Omit<Transaction<T>, "mutations"> & object;Defined in: packages/db/src/types.ts:156
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, TCollection>>;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
TCollection
TCollection extends Collection<T, any, any, any, any> = Collection<T, any, any, any, any>
AI 翻译查看英文原文